Provide SHOPIFY_SUBDOMAIN
, SHOPIFY_EMAIL
and SHOPIFY_PASSWORD
environment variables, and discount.rb
will configure itself.
Supported APIs are
Discount.find(:all)
Discount.find(:first)
Discount.create(...)
Discount#destroy
NOTE: Discount.find(:id)
is not supported
Sample rails console session:
$ SHOPIFY_SUBDOMAIN=demo SHOPIFY_EMAIL=demo@example.com SHOPIFY_PASSWORD=topsecret rails console
Loading development environment (Rails 4.1.0)
2.1.1 :001 > Discount.find(:all)
=> #<ActiveResource::Collection:0x007f9f150da938 @elements=[], @resource_class=Discount, @original_params={}>
2.1.1 :002 > d = Discount.create(code: "ONETWOTHREE", discount_type: "percentage", value: 1)
=> #<Discount:0x007f9f150bbbc8 @attributes={"code"=>"ONETWOTHREE", "discount_type"=>"percentage", "value"=>"1.0", "id"=>9999999, "applies_once"=>false, "applies_to_id"=>nil, "ends_at"=>nil, "minimum_order_amount"=>"0.00", "starts_at"=>"2014-05-10T22:22:40+08:00", "status"=>"enabled", "usage_limit"=>nil, "applies_to_resource"=>nil, "times_used"=>0}, @prefix_options={}, @persisted=true, @remote_errors=nil, @validation_context=nil, @errors=#<ActiveResource::Errors:0x007f9f150bb268 @base=#<Discount:0x007f9f150bbbc8 ...>, @messages={}>>
2.1.1 :003 > Discount.find(:first) == d
=> true
2.1.1 :004 > d.destroy
=> #<Mechanize::File:0x007f9f11fe2b50 @uri=#<URI::HTTPS:0x007f9f15012f78 URL:https://demo.myshopify.com/admin/discounts/9999999.json>, @body="{}", @code="200", @full_path=false, @response={"server"=>"nginx", "date"=>"Sat, 10 May 2014 14:23:00 GMT", "content-type"=>"application/json; charset=utf-8", "transfer-encoding"=>"chunked", "vary"=>"Accept-Encoding", "status"=>"200 OK", "x-xss-protection"=>"1; mode=block", "x-content-type-options"=>"nosniff", "x-ua-compatible"=>"chrome=1", "x-shopid"=>"1234567", "x-shardid"=>"0", "x-shopify-asset-version"=>"ffff", "x-stats-userid"=>"7654321", "x-frame-options"=>"SAMEORIGIN", "cache-control"=>"no-cache, no-store", "set-cookie"=>"request_method=DELETE; path=/", "x-request-id"=>"ffff-ffff", "p3p"=>"CP=\"NOI DSP COR NID ADMa OPTa OUR NOR\"", "content-encoding"=>"gzip"}, @filename="9999999.json">
2.1.1 :005 > Discount.find(:all)
=> #<ActiveResource::Collection:0x007f9f11f50ae8 @elements=[], @resource_class=Discount, @original_params={}>
@SebastianSzturo commented on Oct 27, 2014
Fixed the login issue! Thats the working code as of today.