bigcommerce-oauth-api 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d21d23bfd3d96f62410526c176eef2430ef75b18
4
- data.tar.gz: 68342694e338c0b0442652f273850d30f0351f2f
3
+ metadata.gz: 7f6019efb2862df605d51ddc295b27fe454155a7
4
+ data.tar.gz: 5b10eca0204bc2609c58f2f9e5fcbacafe919d98
5
5
  SHA512:
6
- metadata.gz: f357552ee8681b7e37601bee9e409e4883c96e2d04c6819786f98caeecfa0d25c378c5fb3032703c6a8c936b54d9fd50350fb9b5fd8b1636defa21763a2802bd
7
- data.tar.gz: 162da3158b864d16eda398355e1c408b9533f16931d12b7f6445b04b24f50d3c4a32a8f85d34a4f95afa7a06ce7cf841cb07a5d173deddd72170faefaafbd59b
6
+ metadata.gz: ca140e744fca66c4b14f9b51cdb36c33ae59e470178d56c3dda48acbaab0d346ec6099c532be63113b0ef05632a25c7e5ba4b3600c7cd35fc8edadcf94b10927
7
+ data.tar.gz: 633316c3b35e61ad303afc1dc18f9c97afce27e0f384369392b1b29fcd113fbf0918d1056b3a2d4b9f27f1c7ae2bf1d81bff6e58f259c287d4a3ad3e2dd5151e
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format=documentation
3
+ --backtrace
data/CHANGELOG.md ADDED
@@ -0,0 +1,69 @@
1
+ ### 1.1.2 (2014-11-04)
2
+
3
+ Bugfixes:
4
+
5
+ - fix broken gemspec
6
+ - remove Gemfile.lock from git and add it to gitignore
7
+
8
+ ### 1.1.1 (2014-11-04)
9
+
10
+ Bugfixes:
11
+
12
+ - correct lib folder name and adjust require statements
13
+ - rename repository from bigcommerce-oauth-api-ruby to bugcommerce-oauth-api
14
+ - update markdown badges
15
+
16
+
17
+ ### 1.1.0 (2014-11-02)
18
+
19
+ Features:
20
+
21
+ - add product SKU api
22
+ - add product video api
23
+ - add product rules api
24
+ - add product review api
25
+ - add product option api
26
+ - add product image api
27
+ - add option api
28
+ - add option set api
29
+ - add option set option api
30
+ - add option set value api
31
+ - add googleproductsearch api
32
+ - add product configurable field api
33
+ - add category api
34
+ - add bulk pricing (discount rules) api
35
+ - add brand api
36
+
37
+
38
+ ### 1.0.3 (2014-11-02)
39
+
40
+ Bugfixes:
41
+
42
+ - Change activesupport dependency to >=3 && <5
43
+
44
+ ### 1.0.2 (2014-11-01)
45
+
46
+ Features:
47
+
48
+ - add blog post api
49
+ - add blog tag api
50
+ - add customer api
51
+ - add customer address api
52
+ - add customer group api
53
+ - add geography country api
54
+ - add geography state api
55
+ - add marketing coupon api
56
+ - add order api
57
+ - add order message api
58
+ - add order product api
59
+ - add order shipment api
60
+ - add order shipping address api
61
+ - add payment method api
62
+ - add product api
63
+ - add product custom field api
64
+ - add redirect api
65
+ - add shipping method api
66
+ - add store api (store information)
67
+ - add system api (time)
68
+ - add tax class api
69
+ - add web hook api
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :test do
4
+ gem 'codeclimate-test-reporter', require: nil
5
+ end
6
+
7
+ gemspec
data/README.md ADDED
@@ -0,0 +1,180 @@
1
+ bigcommerce-oauth-api
2
+ ==========================
3
+ [![Gem Version](https://badge.fury.io/rb/bigcommerce-oauth-api.svg)](http://badge.fury.io/rb/bigcommerce-oauth-api)
4
+ [![Code Climate](https://codeclimate.com/github/corthmann/bigcommerce-oauth-api/badges/gpa.svg)](https://codeclimate.com/github/corthmann/bigcommerce-oauth-api)
5
+ [![Test Coverage](https://codeclimate.com/github/corthmann/bigcommerce-oauth-api/badges/coverage.svg)](https://codeclimate.com/github/corthmann/bigcommerce-oauth-api)
6
+ [![Dependency Status](https://gemnasium.com/corthmann/bigcommerce-oauth-api.svg)](https://gemnasium.com/corthmann/bigcommerce-oauth-api)
7
+
8
+ This gem provides a wrapper for the Bigcommerce REST API.
9
+
10
+ Installation
11
+ -------------
12
+ You can install this gem by using the following command:
13
+ ```
14
+ gem install bigcommerce-oauth-api
15
+ ```
16
+ or by adding the the following line to your Gemfile.
17
+ ```
18
+ gem 'bigcommerce-oauth-api'
19
+ ```
20
+
21
+ Configuration
22
+ -------------
23
+ The gem can be configured in two ways. Either by initializing the API with certain options.
24
+ ```
25
+ BigcommerceOAuthAPI.configuration do |config|
26
+ config.store_hash = 'YOU STORE ID'
27
+ config.client_id = 'YOUR CLIENT ID'
28
+ config.access_token = 'YOUR OAUTH ACCESS TOKEN'
29
+ end
30
+ ```
31
+
32
+ Or by passing options to a new client instance.
33
+ ```
34
+ api = BigcommerceOAuthAPI::Client.new(
35
+ :store_hash => 'YOUR STORE ID',
36
+ :config.client_id => 'YOUR CLIENT ID',
37
+ :config.access_token => 'YOUR OAUTH ACCESS TOKEN'
38
+ )
39
+ ```
40
+
41
+ Using the API
42
+ -------------
43
+ Get a list of products:
44
+ ```
45
+ products = api.products
46
+ ```
47
+ Get orders with order_id >= 100
48
+ ```
49
+ orders = api.orders({ min_id: 100 })
50
+ ```
51
+ Get the order with id = 101
52
+ ```
53
+ order = api.order(101)
54
+ ```
55
+ All resource attributes can be accessed both using methods or as a hash with keys as either strings or keys.
56
+ ```
57
+ # each of the following lines return the first name listed in the order billing address
58
+ order.billing_address.first_name
59
+ order['billing_address']['first_name']
60
+ order[:billing_address][:first_name]
61
+ ```
62
+ Update the name of a customer
63
+ ```
64
+ customer = api.update_customer(101, {first_name: 'Christian'})
65
+ ```
66
+ Delete an order shipment
67
+ ```
68
+ order_id = 101
69
+ shipment_id = 1000
70
+ api.delete_order_shipment(order_id, shipment_id)
71
+ ```
72
+ Webhooks
73
+ -------------
74
+ In many applications it is an advantage to receive a callback on events rather than polling information. Such callbacks are commonly called webhooks.
75
+
76
+ The Bigcommerce API allows you to create webhooks for events you want to respond to - for instance every time an order is created.
77
+ ```
78
+ # more information on: https://developer.bigcommerce.com/api/webhooks-getting-started
79
+ new_hook = {
80
+ scope: "store/order/created",
81
+ destination: "https://app.example.com/order-callback",
82
+ is_active: true
83
+ }
84
+ hook = api.create_hook(new_hook)
85
+ ```
86
+ After creating the webhook as shown above a callback (POST) will be sent to 'https://app.example.com/order-callback' every time an order is created.
87
+
88
+ The API also allows you to mange hooks like so:
89
+ ```
90
+ # get a list of the webhooks
91
+ hooks = api.hooks
92
+ # get the webhook with id = 1234
93
+ hook_id = 1234
94
+ hook = api.hook(hook_id)
95
+ # delete the webhook with id = 1234
96
+ api.delete_hook(hook_id)
97
+ ```
98
+
99
+ API Support
100
+ -------------
101
+ The following APIs are currently supported:
102
+
103
+ API | Included from
104
+ --- | ---
105
+ blog post | 1.0.2
106
+ blog tag | 1.0.2
107
+ brand api | 1.1.0
108
+ bulk pricing (discount rules) | 1.1.0
109
+ category | 1.1.0
110
+ customer api | 1.0.2
111
+ customer address | 1.0.2
112
+ customer group | 1.0.2
113
+ geography country | 1.0.2
114
+ geography state | 1.0.2
115
+ marketing coupon | 1.0.2
116
+ option | 1.1.0
117
+ option set | 1.1.0
118
+ option set option | 1.1.0
119
+ option set value | 1.1.0
120
+ order | 1.0.2
121
+ order message | 1.0.2
122
+ order product | 1.0.2
123
+ order shipment | 1.0.2
124
+ order shipping address | 1.0.2
125
+ payment method | 1.0.2
126
+ product | 1.0.2
127
+ product configurable field | 1.1.0
128
+ product custom field | 1.0.2
129
+ product googleproductsearch | 1.1.0
130
+ product image | 1.1.0
131
+ product option | 1.1.0
132
+ product review | 1.1.0
133
+ product rules | 1.1.0
134
+ product video | 1.1.0
135
+ product SKU | 1.1.0
136
+ redirect | 1.0.2
137
+ shipping method api | 1.0.2
138
+ store information | 1.0.2
139
+ system (time) | 1.0.2
140
+ tax class | 1.0.2
141
+ web hook | 1.0.2
142
+
143
+ Getting an OAuth Access Token
144
+ -------------
145
+ Currently the Bigcommerce API is only focused on making the OAuth API available for 3rd party development through Apps.
146
+ This is quite frustrating especially if you want to use the API to make custom integrations for your webshop.
147
+
148
+ However, it is actually possible to aquire access tokens without publishing an App for Bigcommerce.
149
+
150
+ 1. Go to http://developer.bigcommerce.com
151
+
152
+ 2. Login with the same user as the webshop you want to create a token for.
153
+
154
+ 3. Go to "My Apps" and create dummy app (maybe call it "Authentication App")
155
+
156
+ 4. Select the APIs you need and set the Auth Callback Url.
157
+ * This needs to be a HTTPS Url where you can read incomming GET request
158
+
159
+ 5. Go to your webshop and click on "Apps"
160
+
161
+ 6. Select the tab "My Drafts" (which should contain your "Authentication App")
162
+
163
+ 7. Install the "Authentication App" in your webshop.
164
+ * This triggers a callback to your "Auth Callback Url" where you receive a code which can be exchanged for a token.
165
+
166
+ 8. Send a POST request containing the following parameters (to https://login.bigcommerce.com/oauth2/token):
167
+ * client_id (can be found under "My Apps" at developer.bigcommerce.com
168
+ * client_secret (can be found under "My Apps" at developer.bigcommerce.com
169
+ * code (is received in the "Auth Callback")
170
+ * scope (is received in the "Auth Callback")
171
+ * grant_type (is always authorization_code)
172
+ * redirect_uri (your "Auth Callback Url")
173
+ * context (is "stores/{your store hash / id}")
174
+
175
+ 9. Done! The response returns your OAuth Access Token.
176
+
177
+ If you are experiencing problems with the POST call try using the folllowing curl command
178
+ ```
179
+ curl --data "[YOUR POST PARAMETERS]" https://login.bigcommerce.com/oauth2/token
180
+ ```
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+ task :test => :spec
@@ -0,0 +1,25 @@
1
+ require File.expand_path('../lib/bigcommerce-oauth-api/version', __FILE__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'bigcommerce-oauth-api'
5
+ s.version = BigcommerceOAuthAPI::VERSION.dup
6
+ s.date = '2014-11-04'
7
+ s.summary = "Ruby wrapper for the Bigcommerce REST API using OAuth"
8
+ s.description = "Connect Ruby applications with the Bigcommerce REST API using OAuth"
9
+ s.authors = ["Christian Orthmann"]
10
+ s.email = 'christian.orthmann@gmail.com'
11
+ s.require_path = 'lib'
12
+ s.files = `git ls-files`.split("\n") - %w(.rvmrc .gitignore)
13
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") - %w(.rvmrc .gitignore)
14
+ s.homepage = 'http://rubygems.org/gems/bigcommerce-oauth-api'
15
+ s.license = 'MIT'
16
+
17
+ s.add_development_dependency('rake', '~> 10')
18
+ s.add_development_dependency('rspec', '~> 3')
19
+ s.add_development_dependency('webmock', '~> 1')
20
+ s.add_development_dependency('simplecov', '~> 0')
21
+ s.add_development_dependency('simplecov-rcov', '~> 0')
22
+ s.add_runtime_dependency('faraday', '~> 0')
23
+ s.add_runtime_dependency('faraday_middleware', '~> 0')
24
+ s.add_runtime_dependency('activesupport', '>= 3.0.0', '< 5.0.0')
25
+ end
@@ -0,0 +1,11 @@
1
+ require 'bigcommerce-oauth-api/configuration'
2
+ require 'bigcommerce-oauth-api/client'
3
+ require 'bigcommerce-oauth-api/api'
4
+ require 'bigcommerce-oauth-api/client'
5
+ require 'bigcommerce-oauth-api/error'
6
+ require 'bigcommerce-oauth-api/resource'
7
+
8
+ module BigcommerceOAuthAPI
9
+ extend Configuration
10
+
11
+ end
@@ -0,0 +1,28 @@
1
+ require 'bigcommerce-oauth-api/connection'
2
+ require 'bigcommerce-oauth-api/request'
3
+ require 'bigcommerce-oauth-api/base'
4
+
5
+ module BigcommerceOAuthAPI
6
+ class API < Base
7
+ attr_accessor *Configuration::VALID_OPTIONS_KEYS
8
+
9
+ def initialize(options = {})
10
+ merged_options = BigcommerceOAuthAPI.options.merge(options)
11
+
12
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
13
+ send("#{key}=", merged_options[key])
14
+ end
15
+ end
16
+
17
+ def config
18
+ conf = {}
19
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
20
+ conf[key] = send(key)
21
+ end
22
+ conf
23
+ end
24
+
25
+ include Connection
26
+ include Request
27
+ end
28
+ end
@@ -0,0 +1,85 @@
1
+ require 'active_support/inflector'
2
+ require 'bigcommerce-oauth-api/error'
3
+
4
+ module BigcommerceOAuthAPI
5
+ class Base
6
+
7
+ protected
8
+
9
+ def self.with_api_methods(map)
10
+ map.each do |api, method_description|
11
+ api_module = method_description[:api_module]
12
+ api_scope = method_description[:scope]
13
+ path_prefix = (method_description.has_key?(:prefix_paths) ? "#{method_description[:prefix_paths]}/" : nil)
14
+ method_prefix = (method_description.has_key?(:prefix_methods) ? "#{method_description[:prefix_methods]}_" : nil)
15
+ method_description[:methods].each do |method|
16
+ with_action(method, api_module, api_scope, path_prefix, method_prefix)
17
+ end
18
+ end
19
+ end
20
+
21
+ def self.with_action(method, api_module, api_scope, path_prefix = nil, method_prefix = nil)
22
+ is_nested = api_scope != :self
23
+ method_name, method_params, has_options = get_method_name_and_params(method, api_module, api_scope, is_nested, method_prefix)
24
+ method_path = get_method_path(method, api_module, api_scope, is_nested)
25
+ request_method = get_request_method(method)
26
+
27
+ # Ensure that existing methods never are overwritten
28
+ # Raise an error if it is attempted
29
+ if self.method_defined?(:"#{method_name}")
30
+ raise MethodAlreadyDefinedError.new("Method already defined: '#{method_name}'")
31
+ end
32
+
33
+ class_eval %Q{
34
+ def #{method_name}#{method_params}
35
+ #{request_method}("#{path_prefix}#{method_path}"#{( has_options ? ', options' : '')})
36
+ end
37
+ }
38
+ end
39
+
40
+ def self.get_method_name_and_params(method, api_module, api_scope, is_nested = false, method_prefix = nil)
41
+ base = (is_nested ? "#{method_prefix}#{api_scope}_#{api_module}": "#{method_prefix}#{api_module}").to_s
42
+ params_base = "(#{(is_nested ? "#{api_scope}_id, ": '')}"
43
+ has_options = method != :delete
44
+ case method
45
+ when :all
46
+ return base.pluralize, "#{params_base}options = {})", has_options
47
+ when :count
48
+ return "#{base.pluralize}_count", "#{params_base}options = {})", has_options
49
+ when :select
50
+ return base, "#{params_base}id, options = {})", has_options
51
+ when :create
52
+ return "#{method}_#{base}", "#{params_base}options = {})", has_options
53
+ when :update
54
+ return "#{method}_#{base}", "#{params_base}id, options = {})", has_options
55
+ when :delete
56
+ return "#{method}_#{base}", "#{params_base}id)", has_options
57
+ end
58
+ end
59
+
60
+ def self.get_method_path(method, api_module, api_scope, is_nested = false)
61
+ base = (is_nested ? "#{api_scope.to_s.pluralize}/\#{#{api_scope}_id}/#{api_module}": api_module).to_s.pluralize
62
+ case method
63
+ when :all, :create
64
+ return base
65
+ when :count
66
+ return "#{base}/count"
67
+ when :select, :update, :delete
68
+ return "#{base}/\#{id}"
69
+ end
70
+ end
71
+
72
+ def self.get_request_method(method)
73
+ case method
74
+ when :all, :count, :select
75
+ return :get
76
+ when :create
77
+ return :post
78
+ when :update
79
+ return :put
80
+ when :delete
81
+ return :delete
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,60 @@
1
+ require 'bigcommerce-oauth-api/api'
2
+
3
+ module BigcommerceOAuthAPI
4
+ class Client < API
5
+
6
+ ##
7
+ # get server time
8
+ def time
9
+ get('time')
10
+ end
11
+
12
+ ##
13
+ # get basic store information
14
+ def store_information
15
+ get('store')
16
+ end
17
+
18
+ ##
19
+ # Gets the Google Product Search mappings for a product.
20
+ def product_googleproductsearch(product_id, options = {})
21
+ get("products/#{product_id}/googleproductsearch", options)
22
+ end
23
+
24
+ with_api_methods :blog_post => { api_module: :post, scope: :self, methods: [:all, :select, :create, :update, :delete], prefix_paths: 'blog', prefix_methods: 'blog'},
25
+ :blog_tag => { api_module: :tag, scope: :self, methods: [:all], prefix_paths: 'blog', prefix_methods: 'blog'},
26
+ :brand => { api_module: :brand, scope: :self, methods: [:all, :select, :create, :update, :delete]},
27
+ :category => { api_module: :category, scope: :self, methods: [:all, :select, :create, :update, :delete]},
28
+ :customer => { api_module: :customer, scope: :self, methods: [:all, :select, :create, :update, :delete, :count]},
29
+ :customer_address => { api_module: :address, scope: :customer, methods: [:all, :select, :create, :update, :delete]},
30
+ :customer_group => { api_module: :customer_group, scope: :self, methods: [:all, :select, :create, :update, :delete]},
31
+ :geography_country => { api_module: :country, scope: :self, methods: [:all, :select]},
32
+ :geography_state => { api_module: :state, scope: :self, methods: [:all, :select]},
33
+ :marketing_coupons => { api_module: :coupon, scope: :self, methods: [:all, :select, :create, :update, :delete]},
34
+ :option => { api_module: :option, scope: :self, methods: [:all, :select, :create, :update, :delete]},
35
+ :option_set => { api_module: :option_set, scope: :self, methods: [:all, :select, :create, :update, :delete]},
36
+ :option_set_option => { api_module: :option, scope: :option_set, methods: [:all, :select, :create, :update, :delete]},
37
+ :option_set_value => { api_module: :value, scope: :option_set, methods: [:all, :select, :create, :update, :delete]},
38
+ :order => { api_module: :order, scope: :self, methods: [:all, :select, :create, :update, :delete, :count]},
39
+ :order_message => { api_module: :message, scope: :order, methods: [:all, :select]},
40
+ :order_product => { api_module: :product, scope: :order, methods: [:all, :select]},
41
+ :order_shipment => { api_module: :shipment, scope: :order, methods: [:all, :select, :create, :update, :delete]},
42
+ :order_shipping_address => { api_module: :shipping_address, scope: :order, methods: [:all, :select]},
43
+ :payment_method => { api_module: :method, scope: :self, methods: [:all], prefix_paths: 'payments', prefix_methods: 'payment'},
44
+ :product => { api_module: :product, scope: :self, methods: [:all, :select, :create, :update, :delete, :count]},
45
+ :product_custom_field => { api_module: :custom_field, scope: :product, methods: [:all, :select, :create, :update, :delete]},
46
+ :product_discount_rule => { api_module: :discount_rule, scope: :product, methods: [:all, :select, :create, :update, :delete]},
47
+ :product_configurable_field => { api_module: :configurable_field, scope: :product, methods: [:all, :select, :delete]},
48
+ :product_image => { api_module: :image, scope: :product, methods: [:all, :select, :create, :update, :delete]},
49
+ :product_option => { api_module: :option, scope: :product, methods: [:all, :select]},
50
+ :product_review => { api_module: :review, scope: :product, methods: [:all]},
51
+ :product_rule => { api_module: :rule, scope: :product, methods: [:all, :select, :create, :update, :delete]},
52
+ :product_video => { api_module: :video, scope: :product, methods: [:all, :select, :create, :update, :delete]},
53
+ :product_sku => { api_module: :sku, scope: :product, methods: [:all, :select, :create, :update, :delete]},
54
+ :redirect => { api_module: :redirect, scope: :self, methods: [:all, :select, :create, :update, :delete]},
55
+ :shipping_method => { api_module: :method, scope: :self, methods: [:all, :select], prefix_paths: 'shipping', prefix_methods: 'shipping'},
56
+ :tax_class => { api_module: :tax_class, scope: :self, methods: [:all, :select]},
57
+ :web_hook => { api_module: :hook, scope: :self, methods: [:all, :select, :create, :update, :delete]}
58
+
59
+ end
60
+ end