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.
@@ -0,0 +1,46 @@
1
+ require 'faraday'
2
+
3
+ module BigcommerceOAuthAPI
4
+ module Configuration
5
+
6
+ VALID_OPTIONS_KEYS = [
7
+ :store_hash,
8
+ :endpoint,
9
+ :adapter,
10
+ :client_id,
11
+ :access_token,
12
+ :format
13
+ ].freeze
14
+
15
+ DEFAULT_STORE_HASH = nil
16
+ DEFAULT_ENDPOINT = 'https://api.bigcommerce.com/stores'.freeze
17
+ DEFAULT_CLIENT_ID = nil
18
+ DEFAULT_ACCESS_TOKEN = nil
19
+ DEFAULT_FORMAT = :json
20
+ DEFAULT_ADAPTER = Faraday.default_adapter
21
+
22
+ attr_accessor *VALID_OPTIONS_KEYS
23
+
24
+ def self.extended(base)
25
+ base.reset
26
+ end
27
+
28
+ def reset
29
+ self.store_hash = DEFAULT_STORE_HASH
30
+ self.endpoint = DEFAULT_ENDPOINT
31
+ self.format = DEFAULT_FORMAT
32
+ self.client_id = DEFAULT_CLIENT_ID
33
+ self.access_token = DEFAULT_ACCESS_TOKEN
34
+ self.adapter = DEFAULT_ADAPTER
35
+ end
36
+
37
+ def configure
38
+ yield self
39
+ end
40
+
41
+ # Return the configuration values set in this module
42
+ def options
43
+ Hash[ * VALID_OPTIONS_KEYS.map { |key| [key, send(key)] }.flatten ]
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,28 @@
1
+ require 'faraday_middleware'
2
+ Dir[File.expand_path('../../faraday/*.rb', __FILE__)].each { |f| require f }
3
+
4
+ module BigcommerceOAuthAPI
5
+ module Connection
6
+ private
7
+
8
+ def connection
9
+ options = {
10
+ :headers => {
11
+ 'Accept' => "application/#{format}; charset=utf-8",
12
+ 'X-Auth-Client' => client_id,
13
+ 'X-Auth-Token' => access_token
14
+ },
15
+ :url => "#{endpoint}/#{store_hash}/v2/"
16
+ }
17
+
18
+ Faraday::Connection.new(options) do |connection|
19
+ connection.use Faraday::Request::UrlEncoded
20
+ case format.to_s.downcase
21
+ when 'json' then connection.use Faraday::Response::ParseJson
22
+ end
23
+ connection.use FaradayMiddleware::RaiseHttpException
24
+ connection.adapter(adapter)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,26 @@
1
+ module BigcommerceOAuthAPI
2
+ class Error < StandardError
3
+ def inspect
4
+ "#<BigcommerceOAuthAPI::Error: BigcommerceOAuthAPI::Error message=\"#{message}\">"
5
+ end
6
+ end
7
+
8
+ # 400 HTTP
9
+ class BadRequest < Error; end
10
+
11
+ # 404 HTTP
12
+ class NotFound < Error; end
13
+
14
+ # 429 HTTP
15
+ class TooManyRequests < Error; end
16
+
17
+ # 500 HTTP
18
+ class InternalServerError < Error; end
19
+
20
+ # 502 HTTP
21
+ class BadGateway < Error; end
22
+
23
+ # Raised if the client attempts to define an api method that already is defined elsewhere.
24
+ # Specs will catch this type of error since it will be thrown upon initialization.
25
+ class MethodAlreadyDefinedError < Error; end
26
+ end
@@ -0,0 +1,41 @@
1
+ require 'bigcommerce-oauth-api/resource'
2
+
3
+ module BigcommerceOAuthAPI
4
+ module Request
5
+
6
+ def get(path, options = {})
7
+ request(:get, path, options)
8
+ end
9
+
10
+ def post(path, options = {})
11
+ request(:post, path, options)
12
+ end
13
+
14
+ def put(path, options = {})
15
+ request(:put, path, options)
16
+ end
17
+
18
+ def delete(path, options = {})
19
+ request(:delete, path, options)
20
+ end
21
+
22
+ private
23
+
24
+ def request(method, path, options)
25
+ response = connection.send(method) do |request|
26
+ case method
27
+ when :get, :delete
28
+ request.url(path, options)
29
+ when :post, :put
30
+ request.path = path
31
+ request.body = options if !options.empty?
32
+ end
33
+ end
34
+ if response.body.is_a?(Array)
35
+ response.body.map { |resource| Resource.new(resource) }
36
+ else
37
+ Resource.new(response.body)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,56 @@
1
+ require 'active_support/core_ext/hash/indifferent_access'
2
+
3
+ module BigcommerceOAuthAPI
4
+ class Resource
5
+ def initialize(attributes)
6
+ @attributes = HashWithIndifferentAccess.new(attributes)
7
+ end
8
+
9
+ def [](key)
10
+ @attributes[key.to_sym]
11
+ end
12
+
13
+ def []=(key, value)
14
+ @attributes[key.to_sym] = value
15
+ end
16
+
17
+ def respond_to?(method_name)
18
+ super(method_name) ? true : @attributes.include?(method_name.to_s.gsub(/(\?$)|(=$)/, '').to_sym)
19
+ end
20
+
21
+ def method_missing(method_sym, *arguments)
22
+ method_name = method_sym.to_s
23
+ attribute_name = method_name.gsub(/(\?$)|(=$)/, '')
24
+ if @attributes.include?(method_name.to_sym)
25
+ self.instance_eval build_attribute_getter(attribute_name)
26
+ send(method_sym, *arguments)
27
+ else
28
+ super(method_sym, *arguments)
29
+ end
30
+ end
31
+
32
+ def build_attribute_getter(attribute_name)
33
+ "def #{attribute_name}
34
+ if @attributes[:#{attribute_name}] && @attributes[:#{attribute_name}].is_a?(Hash)
35
+ memoize(:#{attribute_name}) do
36
+ self.class.new(@attributes[:#{attribute_name}])
37
+ end
38
+ else
39
+ @attributes[:#{attribute_name}]
40
+ end
41
+ end"
42
+ end
43
+
44
+ private
45
+
46
+ def memoize(name, &block)
47
+ var = instance_variable_get("@#{name.to_s}") rescue nil
48
+ if var.nil? && block_given?
49
+ var = yield
50
+ instance_variable_set("@#{name.to_s}", var)
51
+ end
52
+
53
+ var
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,3 @@
1
+ module BigcommerceOAuthAPI
2
+ VERSION = '1.1.2'.freeze
3
+ end
@@ -0,0 +1,26 @@
1
+ require 'faraday'
2
+
3
+ module FaradayMiddleware
4
+ class RaiseHttpException < Faraday::Middleware
5
+ def call(env)
6
+ @app.call(env).on_complete do |response|
7
+ case response[:status].to_i
8
+ when 400
9
+ raise BigcommerceOAuthAPI::BadRequest, response[:body]
10
+ when 404
11
+ raise BigcommerceOAuthAPI::NotFound, response[:body]
12
+ when 429
13
+ raise BigcommerceOAuthAPI::TooManyRequests, response[:response_headers]['X-Retry-After']
14
+ when 500
15
+ raise BigcommerceOAuthAPI::InternalServerError, response[:body]
16
+ when 502
17
+ raise BigcommerceOAuthAPI::BadGateway, response[:body]
18
+ end
19
+ end
20
+ end
21
+
22
+ def initialize(app)
23
+ super app
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+ require 'bigcommerce-oauth-api/api'
3
+
4
+ module BigcommerceOAuthAPI
5
+ describe BigcommerceOAuthAPI::API do
6
+ before do
7
+ @keys = BigcommerceOAuthAPI::Configuration::VALID_OPTIONS_KEYS
8
+ end
9
+
10
+ describe 'with module configuration' do
11
+ before do
12
+ BigcommerceOAuthAPI.configure do |config|
13
+ @keys.each do |key|
14
+ config.send("#{key}=", key)
15
+ end
16
+ end
17
+ end
18
+
19
+ after do
20
+ BigcommerceOAuthAPI.reset
21
+ end
22
+
23
+ it 'should inherit module configuration' do
24
+ api = described_class.new
25
+ @keys.each do |key|
26
+ expect(api.send(key)).to eql(key)
27
+ end
28
+ end
29
+
30
+ describe 'with class configuration' do
31
+ before do
32
+ @config = {
33
+ :endpoint => 'a',
34
+ :format => 'b',
35
+ :client_id => 'c',
36
+ :access_token => 'd',
37
+ :adapter => 'e',
38
+ :store_hash => 'f'
39
+ }
40
+ end
41
+
42
+ it 'should override module configuration' do
43
+ api = described_class.new
44
+ @config.each do |key, value|
45
+ api.send("#{key}=", value)
46
+ end
47
+
48
+ @keys.each do |key|
49
+ expect(api.send("#{key}")).to eql(@config[key])
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,124 @@
1
+ require 'spec_helper'
2
+ require 'active_support/inflector'
3
+ require 'bigcommerce-oauth-api'
4
+ require 'bigcommerce-oauth-api/client'
5
+
6
+ describe BigcommerceOAuthAPI::Client do
7
+ [
8
+ { api_module: 'post', methods: [:all, :select, :create, :update, :delete], prefix_paths: 'blog', prefix_methods: 'blog'},
9
+ { api_module: 'tag', methods: [:all], prefix_paths: 'blog', prefix_methods: 'blog'},
10
+ { api_module: 'brand', methods: [:all, :select, :create, :update, :delete]},
11
+ { api_module: 'category', methods: [:all, :select, :create, :update, :delete]},
12
+ { api_module: 'customer', methods: [:all, :select, :create, :update, :delete, :count]},
13
+ { api_module: 'customer_group', methods: [:all, :select, :create, :update, :delete]},
14
+ { api_module: 'country', scope: :self, methods: [:all, :select]},
15
+ { api_module: 'state', scope: :self, methods: [:all, :select]},
16
+ { api_module: 'order', methods: [:all, :select, :create, :update, :delete, :count]},
17
+ { api_module: 'method', methods: [:all], prefix_paths: 'payments', prefix_methods: 'payment'},
18
+ { api_module: 'option', methods: [:all, :select, :create, :update, :delete]},
19
+ { api_module: 'option_set', methods: [:all, :select, :create, :update, :delete]},
20
+ { api_module: 'product', methods: [:all, :select, :create, :update, :delete, :count]},
21
+ { api_module: 'coupon', methods: [:all, :select, :create, :update, :delete]},
22
+ { api_module: 'redirect', methods: [:all, :select, :create, :update, :delete]},
23
+ { api_module: 'method', methods: [:all, :select], prefix_paths: 'shipping', prefix_methods: 'shipping'},
24
+ { api_module: 'tax_class', scope: :self, methods: [:all, :select]},
25
+ { api_module: 'hook', methods: [:all, :select, :create, :update, :delete]},
26
+ ]. each do |api_description|
27
+ api_module = api_description[:api_module]
28
+ api_module_pluralized = api_module.pluralize
29
+ path_prefix = (api_description.has_key?(:prefix_paths) ? "#{api_description[:prefix_paths]}/" : nil)
30
+ method_prefix = (api_description.has_key?(:prefix_methods) ? "#{api_description[:prefix_methods]}_" : nil)
31
+
32
+ before do
33
+ @client = BigcommerceOAuthAPI::Client.new(:store_hash => 'TEST_STORE',
34
+ :client_id => 'SECRET_ID',
35
+ :access_token => 'SECRET_TOKEN')
36
+ end
37
+
38
+ if api_description[:methods].include?(:all)
39
+ describe ".#{method_prefix}#{api_module_pluralized}" do
40
+ it "should get a list of #{api_module_pluralized}" do
41
+ stub_get(@client, "#{path_prefix}#{api_module_pluralized}").
42
+ to_return(:headers => { :content_type => "application/#{@client.format}" })
43
+ @client.send("#{method_prefix}#{api_module_pluralized}".to_sym)
44
+ expect(a_get(@client, "#{path_prefix}#{api_module_pluralized}").
45
+ with(:headers => {'X-Auth-Client' => 'SECRET_ID',
46
+ 'X-Auth-Token' => 'SECRET_TOKEN'})).to have_been_made
47
+ end
48
+ end
49
+ end
50
+
51
+ if api_description[:methods].include?(:select)
52
+ describe ".#{method_prefix}#{api_module}" do
53
+ it "gets the #{api_module} with the given id" do
54
+ id = 10
55
+ stub_get(@client, "#{path_prefix}#{api_module_pluralized}/#{id}").
56
+ to_return(:headers => { :content_type => "application/#{@client.format}" })
57
+ @client.send("#{method_prefix}#{api_module}".to_sym, id)
58
+ expect(a_get(@client, "#{path_prefix}#{api_module_pluralized}/#{id}").
59
+ with(:headers => {'X-Auth-Client' => 'SECRET_ID',
60
+ 'X-Auth-Token' => 'SECRET_TOKEN'})).to have_been_made
61
+ end
62
+ end
63
+ end
64
+
65
+ if api_description[:methods].include?(:create)
66
+ describe ".create_#{method_prefix}#{api_module}" do
67
+ it "creates a #{api_module} with the given attributes" do
68
+ options = { name: 'A', description: 'B'}
69
+ stub_post(@client, "#{path_prefix}#{api_module_pluralized}").
70
+ to_return(:body => options.to_json, :headers => { :content_type => "application/#{@client.format}" })
71
+ @client.send("create_#{method_prefix}#{api_module}".to_sym, options)
72
+ expect(a_post(@client, "#{path_prefix}#{api_module_pluralized}").
73
+ with(:body => options,
74
+ :headers => {'X-Auth-Client' => 'SECRET_ID',
75
+ 'X-Auth-Token' => 'SECRET_TOKEN'})).to have_been_made
76
+ end
77
+ end
78
+ end
79
+
80
+ if api_description[:methods].include?(:update)
81
+ describe ".update_#{method_prefix}#{api_module}" do
82
+ it "update the attributes of the #{api_module} with the given id" do
83
+ id = 10
84
+ options = { name: 'A', description: 'B'}
85
+ stub_put(@client, "#{path_prefix}#{api_module_pluralized}/#{id}").
86
+ with(:body => options).
87
+ to_return(:body => '', :headers => { :content_type => "application/#{@client.format}" })
88
+ @client.send("update_#{method_prefix}#{api_module}".to_sym, id, options)
89
+ expect(a_put(@client, "#{path_prefix}#{api_module_pluralized}/#{id}").
90
+ with(:body => options,
91
+ :headers => {'X-Auth-Client' => 'SECRET_ID',
92
+ 'X-Auth-Token' => 'SECRET_TOKEN'})).to have_been_made
93
+ end
94
+ end
95
+ end
96
+
97
+ if api_description[:methods].include?(:delete)
98
+ describe ".delete_#{method_prefix}#{api_module}" do
99
+ it "deletes the #{api_module} with the given id" do
100
+ id = 10
101
+ stub_delete(@client, "#{path_prefix}#{api_module_pluralized}/#{id}").
102
+ to_return(:headers => { :content_type => "application/#{@client.format}" })
103
+ @client.send("delete_#{method_prefix}#{api_module}".to_sym, id)
104
+ expect(a_delete(@client, "#{path_prefix}#{api_module_pluralized}/#{id}").
105
+ with(:headers => {'X-Auth-Client' => 'SECRET_ID',
106
+ 'X-Auth-Token' => 'SECRET_TOKEN'})).to have_been_made
107
+ end
108
+ end
109
+ end
110
+
111
+ if api_description[:methods].include?(:count)
112
+ describe ".#{method_prefix}#{api_module_pluralized}_count" do
113
+ it "returns the number of #{api_module_pluralized}" do
114
+ stub_get(@client, "#{path_prefix}#{api_module_pluralized}/count").
115
+ to_return(:body => '', :headers => { :content_type => "application/#{@client.format}" })
116
+ @client.send("#{method_prefix}#{api_module_pluralized}_count".to_sym)
117
+ expect(a_get(@client, "#{path_prefix}#{api_module_pluralized}/count").
118
+ with(:headers => {'X-Auth-Client' => 'SECRET_ID',
119
+ 'X-Auth-Token' => 'SECRET_TOKEN'})).to have_been_made
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,130 @@
1
+ require 'spec_helper'
2
+ require 'active_support/inflector'
3
+ require 'bigcommerce-oauth-api'
4
+ require 'bigcommerce-oauth-api/client'
5
+
6
+ describe BigcommerceOAuthAPI::Client do
7
+ [
8
+ { api_module: 'product', api_parent_module: 'order', methods: [:all, :select]},
9
+ { api_module: 'shipping_address', api_parent_module: 'order', methods: [:all, :select]},
10
+ { api_module: 'message', api_parent_module: 'order', methods: [:all, :select]},
11
+ { api_module: 'shipment', api_parent_module: 'order', methods: [:all, :select, :create, :update, :delete]},
12
+ { api_module: 'configurable_field', api_parent_module: 'product', methods: [:all, :select, :delete]},
13
+ { api_module: 'custom_field', api_parent_module: 'product', methods: [:all, :select, :create, :update, :delete]},
14
+ { api_module: 'option', api_parent_module: 'option_set', methods: [:all, :select, :create, :update, :delete]},
15
+ { api_module: 'value', api_parent_module: 'option_set', methods: [:all, :select, :create, :update, :delete]},
16
+ { api_module: 'discount_rule', api_parent_module: 'product', methods: [:all, :select, :create, :update, :delete]},
17
+ { api_module: 'image', api_parent_module: 'product', methods: [:all, :select, :create, :update, :delete]},
18
+ { api_module: 'option', api_parent_module: 'product', methods: [:all, :select]},
19
+ { api_module: 'review', api_parent_module: 'product', methods: [:all]},
20
+ { api_module: 'rule', api_parent_module: 'product', methods: [:all, :select, :create, :update, :delete]},
21
+ { api_module: 'video', api_parent_module: 'product', methods: [:all, :select, :create, :update, :delete]},
22
+ { api_module: 'sku', api_parent_module: 'product', methods: [:all, :select, :create, :update, :delete]},
23
+ { api_module: 'address', api_parent_module: 'customer', methods: [:all, :select, :create, :update, :delete]}
24
+ ]. each do |nested_module|
25
+ api_parent_module = nested_module[:api_parent_module]
26
+ api_parent_module_pluralized = nested_module[:api_parent_module].pluralize
27
+ api_module = nested_module[:api_module]
28
+ api_module_pluralized = api_module.pluralize
29
+ path_prefix = (nested_module.has_key?(:prefix_paths) ? "#{nested_module[:prefix_paths]}/" : nil)
30
+ method_prefix = (nested_module.has_key?(:prefix_methods) ? "#{nested_module[:prefix_methods]}_" : nil)
31
+
32
+ before do
33
+ @client = BigcommerceOAuthAPI::Client.new(:store_hash => 'TEST_STORE',
34
+ :client_id => 'SECRET_ID',
35
+ :access_token => 'SECRET_TOKEN')
36
+ end
37
+
38
+ if nested_module[:methods].include?(:all)
39
+ describe ".#{method_prefix}#{api_parent_module}_#{api_module_pluralized}" do
40
+ it "should get a list of #{api_module_pluralized} for the given #{api_parent_module}" do
41
+ parent_id = 10
42
+ stub_get(@client, "#{path_prefix}#{api_parent_module_pluralized}/#{parent_id}/#{api_module_pluralized}").
43
+ to_return(:headers => { :content_type => "application/#{@client.format}" })
44
+ @client.send("#{method_prefix}#{api_parent_module}_#{api_module_pluralized}".to_sym, parent_id)
45
+ expect(a_get(@client, "#{path_prefix}#{api_parent_module_pluralized}/#{parent_id}/#{api_module_pluralized}").
46
+ with(:headers => {'X-Auth-Client' => 'SECRET_ID',
47
+ 'X-Auth-Token' => 'SECRET_TOKEN'})).to have_been_made
48
+ end
49
+ end
50
+ end
51
+
52
+ if nested_module[:methods].include?(:select)
53
+ describe ".#{method_prefix}#{api_parent_module}_#{api_module}" do
54
+ it "gets the #{api_module} with the given id for the given #{api_parent_module}" do
55
+ id = 10
56
+ parent_id = 5
57
+ stub_get(@client, "#{path_prefix}#{api_parent_module_pluralized}/#{parent_id}/#{api_module_pluralized}/#{id}").
58
+ to_return(:headers => { :content_type => "application/#{@client.format}" })
59
+ @client.send("#{method_prefix}#{api_parent_module}_#{api_module}".to_sym, parent_id, id)
60
+ expect(a_get(@client, "#{path_prefix}#{api_parent_module_pluralized}/#{parent_id}/#{api_module_pluralized}/#{id}").
61
+ with(:headers => {'X-Auth-Client' => 'SECRET_ID',
62
+ 'X-Auth-Token' => 'SECRET_TOKEN'})).to have_been_made
63
+ end
64
+ end
65
+ end
66
+
67
+ if nested_module[:methods].include?(:create)
68
+ describe ".create_#{method_prefix}#{api_parent_module}_#{api_module}" do
69
+ it "creates a #{api_module} with the given attributes for the given #{api_parent_module}" do
70
+ options = { name: 'A', description: 'B'}
71
+ parent_id = 5
72
+ stub_post(@client, "#{path_prefix}#{api_parent_module_pluralized}/#{parent_id}/#{api_module_pluralized}").
73
+ to_return(:body => options.to_json, :headers => { :content_type => "application/#{@client.format}" })
74
+ @client.send("create_#{method_prefix}#{api_parent_module}_#{api_module}".to_sym, parent_id, options)
75
+ expect(a_post(@client, "#{path_prefix}#{api_parent_module_pluralized}/#{parent_id}/#{api_module_pluralized}").
76
+ with(:body => options,
77
+ :headers => {'X-Auth-Client' => 'SECRET_ID',
78
+ 'X-Auth-Token' => 'SECRET_TOKEN'})).to have_been_made
79
+ end
80
+ end
81
+ end
82
+
83
+ if nested_module[:methods].include?(:update)
84
+ describe ".update_#{method_prefix}#{api_parent_module}_#{api_module}" do
85
+ it "update the attributes of the #{api_module} with the given id for the #{api_parent_module}" do
86
+ id = 10
87
+ parent_id = 5
88
+ options = { name: 'A', description: 'B'}
89
+ stub_put(@client, "#{path_prefix}#{api_parent_module_pluralized}/#{parent_id}/#{api_module_pluralized}/#{id}").
90
+ with(:body => options).
91
+ to_return(:body => '', :headers => { :content_type => "application/#{@client.format}" })
92
+ @client.send("update_#{method_prefix}#{api_parent_module}_#{api_module}".to_sym, parent_id, id, options)
93
+ expect(a_put(@client, "#{path_prefix}#{api_parent_module_pluralized}/#{parent_id}/#{api_module_pluralized}/#{id}").
94
+ with(:body => options,
95
+ :headers => {'X-Auth-Client' => 'SECRET_ID',
96
+ 'X-Auth-Token' => 'SECRET_TOKEN'})).to have_been_made
97
+ end
98
+ end
99
+ end
100
+
101
+ if nested_module[:methods].include?(:delete)
102
+ describe ".delete_#{method_prefix}#{api_parent_module}_#{api_module}" do
103
+ it "deletes the #{api_module} with the given id for the #{api_parent_module}" do
104
+ id = 10
105
+ parent_id = 5
106
+ stub_delete(@client, "#{path_prefix}#{api_parent_module_pluralized}/#{parent_id}/#{api_module_pluralized}/#{id}").
107
+ to_return(:headers => { :content_type => "application/#{@client.format}" })
108
+ @client.send("delete_#{method_prefix}#{api_parent_module}_#{api_module}".to_sym, parent_id, id)
109
+ expect(a_delete(@client, "#{path_prefix}#{api_parent_module_pluralized}/#{parent_id}/#{api_module_pluralized}/#{id}").
110
+ with(:headers => {'X-Auth-Client' => 'SECRET_ID',
111
+ 'X-Auth-Token' => 'SECRET_TOKEN'})).to have_been_made
112
+ end
113
+ end
114
+ end
115
+
116
+ if nested_module[:methods].include?(:count)
117
+ describe ".#{method_prefix}#{api_module_pluralized}_count" do
118
+ it "returns the number of #{api_module_pluralized} for the #{api_parent_module}" do
119
+ parent_id = 5
120
+ stub_get(@client, "#{path_prefix}#{api_parent_module_pluralized}/#{parent_id}/#{api_module_pluralized}/count").
121
+ to_return(:body => '', :headers => { :content_type => "application/#{@client.format}" })
122
+ @client.send("#{method_prefix}#{api_module_pluralized}_count".to_sym)
123
+ expect(a_get(@client, "#{path_prefix}#{api_parent_module_pluralized}/#{parent_id}/#{api_module_pluralized}/count").
124
+ with(:headers => {'X-Auth-Client' => 'SECRET_ID',
125
+ 'X-Auth-Token' => 'SECRET_TOKEN'})).to have_been_made
126
+ end
127
+ end
128
+ end
129
+ end
130
+ end