shopify_client 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +30 -0
- data/Rakefile +11 -0
- data/lib/shopify_client.rb +10 -0
- data/lib/shopify_client/api/custom_collection.rb +22 -0
- data/lib/shopify_client/api/order.rb +22 -0
- data/lib/shopify_client/api/product.rb +21 -0
- data/lib/shopify_client/api/recurring_application_charge.rb +43 -0
- data/lib/shopify_client/api/script_tag.rb +35 -0
- data/lib/shopify_client/api/shop.rb +16 -0
- data/lib/shopify_client/api/smart_collection.rb +22 -0
- data/lib/shopify_client/api/webhook.rb +34 -0
- data/lib/shopify_client/base.rb +57 -0
- data/lib/shopify_client/client.rb +91 -0
- data/lib/shopify_client/custom_collection.rb +28 -0
- data/lib/shopify_client/error.rb +13 -0
- data/lib/shopify_client/error/client_error.rb +23 -0
- data/lib/shopify_client/error/server_error.rb +15 -0
- data/lib/shopify_client/image.rb +13 -0
- data/lib/shopify_client/order.rb +29 -0
- data/lib/shopify_client/product.rb +22 -0
- data/lib/shopify_client/recurring_application_charge.rb +20 -0
- data/lib/shopify_client/request/content_type.rb +20 -0
- data/lib/shopify_client/response/parse_json.rb +22 -0
- data/lib/shopify_client/response/raise_error.rb +23 -0
- data/lib/shopify_client/script_tag.rb +19 -0
- data/lib/shopify_client/shop.rb +22 -0
- data/lib/shopify_client/smart_collection.rb +28 -0
- data/lib/shopify_client/version.rb +3 -0
- data/lib/shopify_client/webhook.rb +21 -0
- data/shopify_client.gemspec +28 -0
- data/test/fixtures/custom_collection.json +18 -0
- data/test/fixtures/custom_collections.json +19 -0
- data/test/fixtures/order.json +274 -0
- data/test/fixtures/orders.json +276 -0
- data/test/fixtures/product.json +140 -0
- data/test/fixtures/products.json +170 -0
- data/test/fixtures/recurring_application_charge.json +18 -0
- data/test/fixtures/recurring_application_charges.json +34 -0
- data/test/fixtures/script_tag.json +9 -0
- data/test/fixtures/script_tags.json +18 -0
- data/test/fixtures/shop.json +37 -0
- data/test/fixtures/smart_collection.json +25 -0
- data/test/fixtures/smart_collections.json +26 -0
- data/test/fixtures/webhook.json +10 -0
- data/test/fixtures/webhooks.json +20 -0
- data/test/shopify_client/api/custom_collection_spec.rb +54 -0
- data/test/shopify_client/api/order_spec.rb +68 -0
- data/test/shopify_client/api/product_spec.rb +66 -0
- data/test/shopify_client/api/recurring_application_charge_spec.rb +138 -0
- data/test/shopify_client/api/script_tag_spec.rb +109 -0
- data/test/shopify_client/api/shop_spec.rb +30 -0
- data/test/shopify_client/api/smart_collection_spec.rb +54 -0
- data/test/shopify_client/api/webhook_spec.rb +109 -0
- data/test/shopify_client/base_spec.rb +12 -0
- data/test/shopify_client/client_spec.rb +12 -0
- data/test/shopify_client/custom_collection_spec.rb +41 -0
- data/test/shopify_client/error/client_error_spec.rb +19 -0
- data/test/shopify_client/error/server_error_spec.rb +20 -0
- data/test/shopify_client/order_spec.rb +30 -0
- data/test/shopify_client/product_spec.rb +21 -0
- data/test/shopify_client/recurring_application_charge_spec.rb +20 -0
- data/test/shopify_client/script_tag_spec.rb +22 -0
- data/test/shopify_client/shop_spec.rb +14 -0
- data/test/shopify_client/smart_collection_spec.rb +41 -0
- data/test/shopify_client/webhook_spec.rb +22 -0
- data/test/shopify_client_spec.rb +10 -0
- data/test/test_helper.rb +13 -0
- metadata +235 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cca7cd486238903d6162d58b335245ba3192e227
|
4
|
+
data.tar.gz: 53d32ca16edcfcf2976db4647f058e585635e50d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 52d697f782ef5db8c6ca257ad95f17241a7976d14c698180ba3a9071c6bbe806202caa8f728c985773165e17ed7cb2af94f728b15a9f3b3d097fd0eef16f362b
|
7
|
+
data.tar.gz: 000d8a63072eaa2c22b9a6faa963e23acd427033b4fdaebe5c5c70be496173fcdf386240277df31a3eec768b184859113f2fa70599e9a53771424f749f693f08
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Esteban Pastorino
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# ShopifyClient
|
2
|
+
|
3
|
+
ShopifyClient is intended to be a thread-safe client of the Shopify API. [shopify_api](https://github.com/Shopify/shopify_api) gem is great, but due to ActiveResource dependency, it's not thread safe unfortunately.
|
4
|
+
It's heavy influenced by the [twitter gem](https://github.com/sferik/twitter).
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'shopify_client'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install shopify_client
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
TODO: Write usage instructions here
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
|
26
|
+
1. Fork it
|
27
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
28
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
29
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
30
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rake/testtask'
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
|
4
|
+
Rake::TestTask.new do |t|
|
5
|
+
t.libs << "test"
|
6
|
+
t.test_files = FileList['test/**/*_spec.rb', 'test/**/*_test.rb']
|
7
|
+
t.ruby_opts = ['-r./test/test_helper.rb']
|
8
|
+
t.verbose = true
|
9
|
+
end
|
10
|
+
|
11
|
+
task :default => :test
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "shopify_client/custom_collection"
|
2
|
+
|
3
|
+
module ShopifyClient
|
4
|
+
module API
|
5
|
+
|
6
|
+
module CustomCollection
|
7
|
+
|
8
|
+
def custom_collections(params = {})
|
9
|
+
response = get("custom_collections.json", params)
|
10
|
+
ShopifyClient::CustomCollection.array_from_response(response)
|
11
|
+
end
|
12
|
+
|
13
|
+
def custom_collection(id, params = {})
|
14
|
+
response = get("custom_collections/#{id}.json", params)
|
15
|
+
ShopifyClient::CustomCollection.from_response(response)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "shopify_client/order"
|
2
|
+
|
3
|
+
module ShopifyClient
|
4
|
+
module API
|
5
|
+
|
6
|
+
module Order
|
7
|
+
|
8
|
+
def orders(params = {})
|
9
|
+
response = get("orders.json", params)
|
10
|
+
ShopifyClient::Order.array_from_response(response)
|
11
|
+
end
|
12
|
+
|
13
|
+
def order(id, params = {})
|
14
|
+
response = get("orders/#{id}.json", params)
|
15
|
+
ShopifyClient::Order.from_response(response)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "shopify_client/product"
|
2
|
+
|
3
|
+
module ShopifyClient
|
4
|
+
module API
|
5
|
+
|
6
|
+
module Product
|
7
|
+
|
8
|
+
def products(params = {})
|
9
|
+
response = get("products.json", params)
|
10
|
+
ShopifyClient::Product.array_from_response(response)
|
11
|
+
end
|
12
|
+
|
13
|
+
def product(id, params = {})
|
14
|
+
response = get("products/#{id}.json", params)
|
15
|
+
ShopifyClient::Product.from_response(response)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "shopify_client/recurring_application_charge"
|
2
|
+
|
3
|
+
module ShopifyClient
|
4
|
+
module API
|
5
|
+
|
6
|
+
module RecurringApplicationCharge
|
7
|
+
|
8
|
+
def recurring_application_charges(params = {})
|
9
|
+
response = get("recurring_application_charges.json", params)
|
10
|
+
ShopifyClient::RecurringApplicationCharge.array_from_response(response)
|
11
|
+
end
|
12
|
+
|
13
|
+
def current_recurring_application_charge(params = {})
|
14
|
+
charges = recurring_application_charges(params)
|
15
|
+
charges.find{|charge| charge.status == 'active' }
|
16
|
+
end
|
17
|
+
|
18
|
+
def recurring_application_charge(id, params = {})
|
19
|
+
response = get("recurring_application_charges/#{id}.json", params)
|
20
|
+
ShopifyClient::RecurringApplicationCharge.from_response(response)
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_recurring_application_charge(attributes)
|
24
|
+
response = post("recurring_application_charges.json", recurring_application_charge: attributes)
|
25
|
+
ShopifyClient::RecurringApplicationCharge.from_response(response)
|
26
|
+
end
|
27
|
+
|
28
|
+
def activate_recurring_application_charge(id_or_object)
|
29
|
+
id = id_or_object.is_a?(ShopifyClient::RecurringApplicationCharge) ? id_or_object.id : id_or_object
|
30
|
+
post("recurring_application_charges/#{id}/activate.json")
|
31
|
+
true
|
32
|
+
end
|
33
|
+
|
34
|
+
def cancel_recurring_application_charge(id_or_object)
|
35
|
+
id = id_or_object.is_a?(ShopifyClient::RecurringApplicationCharge) ? id_or_object.id : id_or_object
|
36
|
+
delete("recurring_application_charges/#{id}.json")
|
37
|
+
true
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "shopify_client/script_tag"
|
2
|
+
|
3
|
+
module ShopifyClient
|
4
|
+
module API
|
5
|
+
|
6
|
+
module ScriptTag
|
7
|
+
|
8
|
+
def script_tags(params = {})
|
9
|
+
response = get("script_tags.json", params)
|
10
|
+
ShopifyClient::ScriptTag.array_from_response(response)
|
11
|
+
end
|
12
|
+
|
13
|
+
def script_tag(id, params = {})
|
14
|
+
response = get("script_tags/#{id}.json", params)
|
15
|
+
ShopifyClient::ScriptTag.from_response(response)
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_script_tag(attributes)
|
19
|
+
response = post("script_tags.json", script_tag: attributes)
|
20
|
+
ShopifyClient::ScriptTag.from_response(response)
|
21
|
+
end
|
22
|
+
|
23
|
+
def destroy_script_tag(id_or_object)
|
24
|
+
id = id_or_object.is_a?(ShopifyClient::ScriptTag) ? id_or_object.id : id_or_object
|
25
|
+
delete("script_tags/#{id}.json")
|
26
|
+
true
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "shopify_client/smart_collection"
|
2
|
+
|
3
|
+
module ShopifyClient
|
4
|
+
module API
|
5
|
+
|
6
|
+
module SmartCollection
|
7
|
+
|
8
|
+
def smart_collections(params = {})
|
9
|
+
response = get("smart_collections.json", params)
|
10
|
+
ShopifyClient::SmartCollection.array_from_response(response)
|
11
|
+
end
|
12
|
+
|
13
|
+
def smart_collection(id, params = {})
|
14
|
+
response = get("smart_collections/#{id}.json", params)
|
15
|
+
ShopifyClient::SmartCollection.from_response(response)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "shopify_client/webhook"
|
2
|
+
|
3
|
+
module ShopifyClient
|
4
|
+
module API
|
5
|
+
|
6
|
+
module Webhook
|
7
|
+
|
8
|
+
def webhooks(params = {})
|
9
|
+
response = get("webhooks.json", params)
|
10
|
+
ShopifyClient::Webhook.array_from_response(response)
|
11
|
+
end
|
12
|
+
|
13
|
+
def webhook(id, params = {})
|
14
|
+
response = get("webhooks/#{id}.json", params)
|
15
|
+
ShopifyClient::Webhook.from_response(response)
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_webhook(attributes)
|
19
|
+
response = post("webhooks.json", webhook: attributes)
|
20
|
+
ShopifyClient::Webhook.from_response(response)
|
21
|
+
end
|
22
|
+
|
23
|
+
def destroy_webhook(id_or_object)
|
24
|
+
id = id_or_object.is_a?(ShopifyClient::Webhook) ? id_or_object.id : id_or_object
|
25
|
+
delete("webhooks/#{id}.json")
|
26
|
+
true
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module ShopifyClient
|
2
|
+
class Base
|
3
|
+
|
4
|
+
attr_reader :attributes
|
5
|
+
alias to_h attributes
|
6
|
+
alias to_hash attributes
|
7
|
+
alias to_hsh attributes
|
8
|
+
|
9
|
+
# Define methods that retrieve the value from an initialized instance variable Hash, using the attribute as a key
|
10
|
+
def self.hattr_reader(*attrs)
|
11
|
+
mod = Module.new do
|
12
|
+
attrs.each do |attribute|
|
13
|
+
define_method attribute do
|
14
|
+
@attributes[attribute.to_sym]
|
15
|
+
end
|
16
|
+
define_method "#{attribute}?" do
|
17
|
+
!!@attributes[attribute.to_sym]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
const_set(:HashAttributes, mod)
|
22
|
+
include mod
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.from_response(response)
|
26
|
+
new parse_single(response[:body])
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.array_from_response(response)
|
30
|
+
parse_array(response[:body]).map do |attributes|
|
31
|
+
new attributes
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.parse_single(body)
|
36
|
+
if body
|
37
|
+
body[single_name]
|
38
|
+
else
|
39
|
+
{}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.parse_array(body)
|
44
|
+
if body
|
45
|
+
body[plural_name]
|
46
|
+
else
|
47
|
+
[]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def initialize(attributes)
|
52
|
+
@attributes = attributes
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'shopify_client/api/custom_collection'
|
3
|
+
require 'shopify_client/api/order'
|
4
|
+
require 'shopify_client/api/product'
|
5
|
+
require 'shopify_client/api/recurring_application_charge'
|
6
|
+
require 'shopify_client/api/script_tag'
|
7
|
+
require 'shopify_client/api/shop'
|
8
|
+
require 'shopify_client/api/smart_collection'
|
9
|
+
require 'shopify_client/api/webhook'
|
10
|
+
require 'shopify_client/request/content_type'
|
11
|
+
require 'shopify_client/response/parse_json'
|
12
|
+
require 'shopify_client/response/raise_error'
|
13
|
+
|
14
|
+
module ShopifyClient
|
15
|
+
|
16
|
+
class Client
|
17
|
+
include ShopifyClient::API::CustomCollection
|
18
|
+
include ShopifyClient::API::Order
|
19
|
+
include ShopifyClient::API::Product
|
20
|
+
include ShopifyClient::API::RecurringApplicationCharge
|
21
|
+
include ShopifyClient::API::ScriptTag
|
22
|
+
include ShopifyClient::API::Shop
|
23
|
+
include ShopifyClient::API::SmartCollection
|
24
|
+
include ShopifyClient::API::Webhook
|
25
|
+
|
26
|
+
def self.normalize_url(url)
|
27
|
+
myshopify_domain = url.match(/(https?:\/\/)?(.+\.myshopify\.com)/)
|
28
|
+
if myshopify_domain
|
29
|
+
myshopify_domain = myshopify_domain[2]
|
30
|
+
"https://#{myshopify_domain}/admin"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def initialize(url, token, options = {})
|
35
|
+
@token = token
|
36
|
+
@url = self.class.normalize_url url
|
37
|
+
end
|
38
|
+
|
39
|
+
# Perform an HTTP GET request
|
40
|
+
def get(path, params={})
|
41
|
+
request(:get, path, params)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Perform an HTTP POST request
|
45
|
+
def post(path, params={})
|
46
|
+
request(:post, path, params)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Perform an HTTP PUT request
|
50
|
+
def put(path, params={})
|
51
|
+
request(:put, path, params)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Perform an HTTP DELETE request
|
55
|
+
def delete(path, params={})
|
56
|
+
request(:delete, path, params)
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def request(method, path, params)
|
62
|
+
connection.send(method.to_sym, path, params).env
|
63
|
+
end
|
64
|
+
|
65
|
+
def connection
|
66
|
+
@connection ||= Faraday.new(@url, connection_options)
|
67
|
+
end
|
68
|
+
|
69
|
+
def connection_options
|
70
|
+
{
|
71
|
+
:headers => {
|
72
|
+
:accept => 'application/json',
|
73
|
+
:user_agent => "ShopifyClient Ruby Gem #{ShopifyClient::VERSION}",
|
74
|
+
'X-Shopify-Access-Token' => @token
|
75
|
+
},
|
76
|
+
:builder => connection_middleware
|
77
|
+
}
|
78
|
+
end
|
79
|
+
|
80
|
+
def connection_middleware
|
81
|
+
@builder ||= Faraday::Builder.new do |builder|
|
82
|
+
builder.use ShopifyClient::Request::ContentType
|
83
|
+
builder.use ShopifyClient::Response::RaiseError
|
84
|
+
builder.use ShopifyClient::Response::ParseJson
|
85
|
+
builder.adapter Faraday.default_adapter
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|