bigcommerce 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +6 -6
- data/Rakefile +6 -13
- data/bigcommerce.gemspec +18 -11
- data/lib/big_commerce.rb +2 -0
- data/lib/bigcommerce.rb +5 -11
- data/lib/bigcommerce/api.rb +133 -89
- data/lib/bigcommerce/connection.rb +94 -73
- data/lib/bigcommerce/version.rb +6 -0
- data/spec/models/api_spec.rb +112 -0
- data/spec/models/connection_spec.rb +91 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/support/fixture_helpers.rb +9 -0
- metadata +146 -56
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
|
1
|
+
Bigcommerce API V2 - Ruby Client
|
2
2
|
================================
|
3
3
|
|
4
|
-
This library provides a wrapper around the
|
4
|
+
This library provides a wrapper around the Bigcommerce REST API for use within
|
5
5
|
Ruby apps or via the console.
|
6
6
|
|
7
7
|
Note
|
@@ -19,7 +19,7 @@ Requirements
|
|
19
19
|
|
20
20
|
To connect to the API, you need the following credentials:
|
21
21
|
|
22
|
-
- Secure URL pointing to a
|
22
|
+
- Secure URL pointing to a Bigcommerce store
|
23
23
|
- Username of an authorized admin user of the store
|
24
24
|
- API key for the user
|
25
25
|
|
@@ -46,7 +46,7 @@ follows:
|
|
46
46
|
```
|
47
47
|
require 'bigcommerce'
|
48
48
|
|
49
|
-
api =
|
49
|
+
api = Bigcommerce::Api.new({
|
50
50
|
:store_url => "https://store.mybigcommerce.com",
|
51
51
|
:username => "admin",
|
52
52
|
:api_key => "d81aada4c19c34d913e18f07fd7f36ca"
|
@@ -71,7 +71,7 @@ The API object acts as a gateway to all top level resources in the V2 API.
|
|
71
71
|
```
|
72
72
|
$ irb
|
73
73
|
>
|
74
|
-
> api =
|
74
|
+
> api = Bigcommerce::Api.new(...)
|
75
75
|
>
|
76
76
|
> api.get_products.each { |product| puts product.name }
|
77
77
|
>
|
@@ -83,7 +83,7 @@ $ irb
|
|
83
83
|
> category.name = "Laptops"
|
84
84
|
> category.update
|
85
85
|
>
|
86
|
-
> brand =
|
86
|
+
> brand = Bigcommerce::Api::Brand.new
|
87
87
|
> brand.name = "Samsung"
|
88
88
|
> brand.create
|
89
89
|
>
|
data/Rakefile
CHANGED
@@ -1,16 +1,9 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'ci/reporter/rake/rspec'
|
3
|
+
require 'rspec/core/rake_task'
|
1
4
|
|
2
|
-
|
3
|
-
|
4
|
-
task :build do
|
5
|
-
sh "gem build bigcommerce.gemspec"
|
6
|
-
end
|
7
|
-
|
8
|
-
task :publish => :build do
|
9
|
-
sh "gem push bigcommerce-#{BigCommerce::VERSION}.gem"
|
10
|
-
end
|
11
|
-
|
12
|
-
task :clean do
|
13
|
-
sh "rm *.gem"
|
5
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
6
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
14
7
|
end
|
15
8
|
|
16
|
-
task :
|
9
|
+
task :default => ['ci:setup:rspec', :spec]
|
data/bigcommerce.gemspec
CHANGED
@@ -1,16 +1,23 @@
|
|
1
|
-
|
2
|
-
require 'lib/bigcommerce'
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/bigcommerce/version', __FILE__)
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
|
-
s.
|
6
|
-
s.
|
5
|
+
s.add_dependency('activesupport')
|
6
|
+
s.add_dependency('json')
|
7
|
+
s.add_development_dependency("ci_reporter")
|
8
|
+
s.add_development_dependency("fakeweb")
|
9
|
+
s.add_development_dependency("mocha")
|
10
|
+
s.add_development_dependency("rake")
|
11
|
+
s.add_development_dependency("rspec", '~> 2.11')
|
12
|
+
s.authors = ["Bigcommerce"]
|
7
13
|
s.date = Time.now.strftime("%Y-%m-%d")
|
8
|
-
s.
|
14
|
+
s.description = "Enables Ruby applications to communicate with the Bigcommerce API V2."
|
9
15
|
s.email = "dev-accounts@bigcommerce.com"
|
10
|
-
s.
|
11
|
-
s.description = "Enables Ruby applications to communicate with the BigCommerce API V2 (currently in beta trial)."
|
16
|
+
s.files = ["LICENSE", "Rakefile", "README.md", "bigcommerce.gemspec"] + Dir['./**/*.rb'] + Dir['./**/*.crt']
|
12
17
|
s.has_rdoc = false
|
13
|
-
s.
|
14
|
-
s.
|
15
|
-
s.
|
16
|
-
|
18
|
+
s.homepage = "http://github.com/bigcommerce/bigcommerce-api-ruby"
|
19
|
+
s.name = "bigcommerce"
|
20
|
+
s.summary = "Enables Ruby applications to communicate with the Bigcommerce API"
|
21
|
+
s.test_files = Dir.glob('spec/**/*_spec.rb')
|
22
|
+
s.version = Bigcommerce::VERSION
|
23
|
+
end
|
data/lib/big_commerce.rb
ADDED
data/lib/bigcommerce.rb
CHANGED
@@ -1,13 +1,7 @@
|
|
1
1
|
require "cgi"
|
2
|
-
require "uri"
|
3
|
-
require "net/https"
|
4
|
-
|
5
|
-
require "rubygems"
|
6
2
|
require "json"
|
7
|
-
|
8
|
-
require
|
9
|
-
require
|
10
|
-
|
11
|
-
|
12
|
-
VERSION = "0.0.5"
|
13
|
-
end
|
3
|
+
require "net/https"
|
4
|
+
require "uri"
|
5
|
+
require 'bigcommerce/api'
|
6
|
+
require 'bigcommerce/connection'
|
7
|
+
require 'bigcommerce/version'
|
data/lib/bigcommerce/api.rb
CHANGED
@@ -1,91 +1,135 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
def get_count(result)
|
79
|
-
result["count"]
|
80
|
-
end
|
81
|
-
|
82
|
-
def get_resource(result)
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
def get_collection(result)
|
87
|
-
|
1
|
+
module Bigcommerce
|
2
|
+
class Api
|
3
|
+
|
4
|
+
def initialize(configuration={})
|
5
|
+
@connection = Connection.new(configuration)
|
6
|
+
end
|
7
|
+
|
8
|
+
# Added getter to ensure configuration is correct
|
9
|
+
def connection
|
10
|
+
@connection
|
11
|
+
end
|
12
|
+
|
13
|
+
def store_url=(store_url)
|
14
|
+
@connection.store_url = store_url
|
15
|
+
end
|
16
|
+
|
17
|
+
def username=(username)
|
18
|
+
@connection.username = username
|
19
|
+
end
|
20
|
+
|
21
|
+
def api_key=(api_key)
|
22
|
+
@connection.api_key = api_key
|
23
|
+
end
|
24
|
+
|
25
|
+
def verify_peer=(verify)
|
26
|
+
@connection.verify_peer = verify
|
27
|
+
end
|
28
|
+
|
29
|
+
def ca_file=(path)
|
30
|
+
@connection.ca_file = path
|
31
|
+
end
|
32
|
+
|
33
|
+
# Returns the date formatted as
|
34
|
+
# RFC 2822 string
|
35
|
+
def to_rfc2822(datetime)
|
36
|
+
datetime.strftime("%a, %d %b %Y %H:%M:%S %z")
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_time
|
40
|
+
@connection.get '/time'
|
41
|
+
end
|
42
|
+
|
43
|
+
def get_products(params={})
|
44
|
+
@connection.get '/products'
|
45
|
+
end
|
46
|
+
|
47
|
+
def get_products_count
|
48
|
+
@connection.get '/products/count/'
|
49
|
+
end
|
50
|
+
|
51
|
+
def get_brands
|
52
|
+
@connection.get '/brands'
|
53
|
+
end
|
54
|
+
|
55
|
+
def get_product(id)
|
56
|
+
@connection.get '/products/' + id.to_s
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_categories
|
60
|
+
@connection.get '/categories'
|
61
|
+
end
|
62
|
+
|
63
|
+
def get_categories_count
|
64
|
+
@connection.get '/categories/count/'
|
65
|
+
end
|
66
|
+
|
67
|
+
def get_category(id)
|
68
|
+
@connection.get '/categories/' + id.to_s
|
69
|
+
end
|
70
|
+
|
71
|
+
def get_orders(params={})
|
72
|
+
@connection.get('/orders', :params => params)
|
73
|
+
end
|
74
|
+
|
75
|
+
def get_orders_by_date(date, params={})
|
76
|
+
if date.is_a?(String)
|
77
|
+
date = DateTime.parse(date)
|
88
78
|
end
|
79
|
+
date = to_rfc2822(date)
|
80
|
+
@connection.get('/orders', :params => params.merge!(:min_date_created => CGI::escape(date)))
|
81
|
+
end
|
89
82
|
|
90
|
-
|
91
|
-
|
83
|
+
def get_orders_count
|
84
|
+
get_count @connection.get '/orders/count'
|
85
|
+
end
|
86
|
+
|
87
|
+
def get_order(id)
|
88
|
+
@connection.get '/orders/' + id.to_s
|
89
|
+
end
|
90
|
+
|
91
|
+
def get_order_products(id)
|
92
|
+
@connection.get '/orders/' + id.to_s + '/products'
|
93
|
+
end
|
94
|
+
|
95
|
+
def get_orders_modified_since(datetime)
|
96
|
+
@connection.get('/orders', :headers => {'If-Modified-Since' => CGI::escape(to_rfc2822(datetime))})
|
97
|
+
end
|
98
|
+
|
99
|
+
def get_customers(_filters = {})
|
100
|
+
url_filters = _filters.map{|k,v| "#{k}=#{v}"}.join("&")
|
101
|
+
@connection.get "/customers#{url_filters.present? ? ("?" + url_filters) : ""}"
|
102
|
+
end
|
103
|
+
|
104
|
+
def get_customer(id)
|
105
|
+
@connection.get '/customers/' + id.to_s
|
106
|
+
end
|
107
|
+
|
108
|
+
def get_customer_count
|
109
|
+
@connection.get '/customers/count'
|
110
|
+
end
|
111
|
+
|
112
|
+
def create_product(attributes)
|
113
|
+
@connection.post('/products', :body => attributes.to_xml(:root => 'product'))
|
114
|
+
end
|
115
|
+
|
116
|
+
def update_product(id, attributes)
|
117
|
+
@connection.put("/products/#{id}", :body => attributes.to_xml(:root => 'product'))
|
118
|
+
end
|
119
|
+
|
120
|
+
private
|
121
|
+
|
122
|
+
def get_count(result)
|
123
|
+
result["count"]
|
124
|
+
end
|
125
|
+
|
126
|
+
def get_resource(result)
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
def get_collection(result)
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
end
|
@@ -1,86 +1,107 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
1
|
+
module Bigcommerce
|
2
|
+
class Connection
|
3
|
+
|
4
|
+
def initialize(configuration)
|
5
|
+
@configuration = configuration
|
6
|
+
end
|
7
|
+
|
8
|
+
def store_url=(store_url)
|
9
|
+
@configuration[:store_url] = store_url
|
10
|
+
end
|
11
|
+
|
12
|
+
def username=(username)
|
13
|
+
@configuration[:username] = username
|
14
|
+
end
|
15
|
+
|
16
|
+
def api_key=(api_key)
|
17
|
+
@configuration[:api_key] = api_key
|
18
|
+
end
|
19
|
+
|
20
|
+
def verify_peer=(verify)
|
21
|
+
@configuration[:verify_peer] = verify
|
22
|
+
end
|
23
|
+
|
24
|
+
def ca_file=(path)
|
25
|
+
@configuration.ca_file = path
|
26
|
+
end
|
27
|
+
|
28
|
+
def get(path, options = {})
|
29
|
+
request(:get, path, options)
|
30
|
+
end
|
31
|
+
|
32
|
+
def post(path, options = {})
|
33
|
+
request(:post, path, options)
|
34
|
+
end
|
35
|
+
|
36
|
+
def put(path, options = {})
|
37
|
+
request(:put, path, options)
|
38
|
+
end
|
39
|
+
|
40
|
+
def delete(path, options = {})
|
41
|
+
request(:delete, path, options)
|
42
|
+
end
|
43
|
+
|
44
|
+
def request(method, path, options = {})
|
45
|
+
body, params = options.values_at(:body, :params)
|
46
|
+
headers = options[:headers] || {}
|
47
|
+
url = @configuration[:store_url] + '/api/v2' + path
|
48
|
+
param_string = hash_to_params(params) unless params.nil? || params.empty?
|
49
|
+
|
50
|
+
unless (param_string.nil? || param_string.empty?)
|
51
|
+
uri = URI.parse("#{url}?#{param_string}")
|
52
|
+
else
|
53
|
+
uri = URI.parse(url)
|
54
|
+
end
|
55
|
+
|
56
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
51
57
|
http.use_ssl = true
|
52
|
-
|
58
|
+
|
53
59
|
if @configuration.has_key?(:verify_peer) && @configuration[:verify_peer]
|
54
|
-
http.verify_mode =
|
60
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
55
61
|
else
|
56
62
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
57
63
|
end
|
58
|
-
|
64
|
+
|
59
65
|
http.ca_file = @configuration[:ca_path] if @configuration.has_key?(:ca_path)
|
60
66
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
+
request = case method
|
68
|
+
when :get then
|
69
|
+
Net::HTTP::Get.new(uri.request_uri)
|
70
|
+
when :post then
|
71
|
+
Net::HTTP::Post.new(uri.request_uri)
|
72
|
+
when :put then
|
73
|
+
Net::HTTP::Put.new(uri.request_uri)
|
74
|
+
when :delete then
|
75
|
+
Net::HTTP::Delete.new(uri.request_uri)
|
76
|
+
end
|
77
|
+
|
78
|
+
request.basic_auth(@configuration[:username], @configuration[:api_key])
|
79
|
+
request.add_field 'Accept', 'application/json'
|
80
|
+
request.add_field 'Content-Type', 'application/json'
|
81
|
+
headers.each { |k,v| request.add_field(k, v) }
|
82
|
+
|
83
|
+
response = http.request(request)
|
84
|
+
|
85
|
+
return case response
|
86
|
+
when Net::HTTPSuccess, Net::HTTPRedirection
|
87
|
+
JSON.parse(response.body || "{}")
|
88
|
+
else
|
89
|
+
false
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def hash_to_params(hash)
|
94
|
+
return nil if hash.nil? || hash.empty?
|
67
95
|
|
68
|
-
|
69
|
-
|
70
|
-
request.add_field 'Content-Type', 'application/json'
|
96
|
+
# convert the hash to URL params
|
97
|
+
return hash.map {|pair| pair.join("=")}.join("&")
|
71
98
|
|
72
|
-
response = http.request(request)
|
73
99
|
|
74
|
-
|
75
|
-
|
76
|
-
JSON.parse(response.body || "{}")
|
77
|
-
else false
|
78
|
-
end
|
79
|
-
end
|
100
|
+
end
|
101
|
+
end
|
80
102
|
|
81
|
-
end
|
82
103
|
|
83
|
-
|
104
|
+
class HttpError < Exception
|
84
105
|
|
85
|
-
|
86
|
-
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Bigcommerce::Api do
|
4
|
+
before do
|
5
|
+
FakeWeb.allow_net_connect = false
|
6
|
+
FakeWeb.register_uri(:get, %r|https://test:12345@store-12345.mybigcommerce.com/api/v2/orders|, :body => load_json_fixture('order'), :status => 200, :content_type => "text/json")
|
7
|
+
FakeWeb.register_uri(:get, %r|https://test:12345@store-12345.mybigcommerce.com/api/v2/time|, :body => load_json_fixture('time'), :status => 200, :content_type => "text/json")
|
8
|
+
end
|
9
|
+
after do
|
10
|
+
FakeWeb.clean_registry
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:api) do
|
14
|
+
Bigcommerce::Api.new({
|
15
|
+
:store_url => "https://store-12345.mybigcommerce.com",
|
16
|
+
:username => "test", :api_key => "12345"
|
17
|
+
})
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:rfc2822_datetime) { "Tue, 13 Mar 2012 12:45:26 +0000" }
|
21
|
+
let(:rfc2822_date) { "Mon, 12 Mar 2012 00:00:00 +0000" }
|
22
|
+
|
23
|
+
describe "Time" do
|
24
|
+
it "converts times to RFC 2822 format" do
|
25
|
+
api.to_rfc2822(DateTime.parse('2012-03-13 12:45:26 +0000')).should eql rfc2822_datetime
|
26
|
+
end
|
27
|
+
it "converts dates to RFC 2822 format" do
|
28
|
+
api.to_rfc2822(DateTime.parse('2012-03-12 00:00:00 +0000')).should eql rfc2822_date
|
29
|
+
end
|
30
|
+
it "retrieves the current time from the store" do
|
31
|
+
api.connection.should_receive(:get).once.with("/time")
|
32
|
+
api.get_time
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "Orders" do
|
37
|
+
it "retrieves an order by ID" do
|
38
|
+
api.connection.should_receive(:get).once.with("/orders/100")
|
39
|
+
api.get_order(100)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "retrieves orders" do
|
43
|
+
api.connection.should_receive(:get).once.with("/orders", :params => {})
|
44
|
+
api.get_orders
|
45
|
+
end
|
46
|
+
|
47
|
+
it "retrieves orders with pagination" do
|
48
|
+
api.connection.should_receive(:get).once.with("/orders", :params => {:page => 2})
|
49
|
+
api.get_orders(:page => 2)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "retrieves orders with limit" do
|
53
|
+
api.connection.should_receive(:get).once.with("/orders", :params => {:limit => 10})
|
54
|
+
api.get_orders(:limit => 10)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "retrieves orders with pagination and limit" do
|
58
|
+
api.connection.should_receive(:get).once.with("/orders", :params => {:limit => 10, :page => 2})
|
59
|
+
api.get_orders(:limit => 10, :page => 2)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "converts from DateTime when retrieving orders by date" do
|
63
|
+
api.connection.should_receive(:get).once.with("/orders", :params => {:min_date_created => CGI::escape(rfc2822_datetime)})
|
64
|
+
api.get_orders_by_date(DateTime.parse('2012-03-13 12:45:26 GMT'))
|
65
|
+
end
|
66
|
+
|
67
|
+
it "converts from DateTime when retrieving orders by date with pagination" do
|
68
|
+
api.connection.should_receive(:get).once.with("/orders", :params => {:min_date_created => CGI::escape(rfc2822_datetime), :page => 2})
|
69
|
+
api.get_orders_by_date(DateTime.parse('2012-03-13 12:45:26 GMT'), :page => 2)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "converts from Date when retrieving orders by date" do
|
73
|
+
api.connection.should_receive(:get).once.with("/orders", :params => {:min_date_created => CGI::escape(rfc2822_date)})
|
74
|
+
api.get_orders_by_date(Date.parse("2012-03-12"))
|
75
|
+
end
|
76
|
+
|
77
|
+
it "converts from a datetime string when retrieving orders by date" do
|
78
|
+
api.connection.should_receive(:get).once.with("/orders", :params => {:min_date_created=> CGI::escape(rfc2822_datetime)})
|
79
|
+
api.connection.should_receive(:get).once.with("/orders", :params => {:min_date_created=> CGI::escape(rfc2822_date)})
|
80
|
+
|
81
|
+
api.get_orders_by_date('2012-03-13 12:45:26 GMT')
|
82
|
+
api.get_orders_by_date('2012-03-12')
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#get_orders_modified_since' do
|
86
|
+
it "retrieves orders modified since date-time" do
|
87
|
+
api.connection.should_receive(:get).with('/orders', :headers => {'If-Modified-Since' => CGI::escape(rfc2822_datetime)})
|
88
|
+
api.get_orders_modified_since(DateTime.parse(rfc2822_datetime))
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "Products" do
|
93
|
+
describe '#create_product' do
|
94
|
+
before { attributes.stub(:to_xml).with(:root => 'product') { 'product_xml' } }
|
95
|
+
let(:attributes) { stub(:attributes) }
|
96
|
+
it "creates product with passed attributes" do
|
97
|
+
api.connection.should_receive(:post).with('/products', :body => 'product_xml')
|
98
|
+
api.create_product(attributes)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe '#update_product' do
|
103
|
+
before { attributes.stub(:to_xml).with(:root => 'product') { 'product_xml' } }
|
104
|
+
let(:attributes) { stub(:attributes) }
|
105
|
+
it "updates product with passed attributes" do
|
106
|
+
api.connection.should_receive(:put).with('/products/123', :body => 'product_xml')
|
107
|
+
api.update_product(123, attributes)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples_for "request method accepting optional params and headers" do
|
4
|
+
it "sends request with no params" do
|
5
|
+
connection.should_receive(:request).once.with(http_method, path, {})
|
6
|
+
connection.send(http_method, path)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "sends request with params" do
|
10
|
+
connection.should_receive(:request).once.with(http_method, path, :params => {:page => 3})
|
11
|
+
connection.send(http_method, path, :params => {:page => 3})
|
12
|
+
end
|
13
|
+
|
14
|
+
it "sends request with headers" do
|
15
|
+
connection.should_receive(:request).once.with(http_method, "/orders", :headers => {'Some-Header' => 'abc'})
|
16
|
+
connection.send(http_method, path, :headers => {'Some-Header' => 'abc'})
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe Bigcommerce::Connection do
|
21
|
+
before { FakeWeb.allow_net_connect = false }
|
22
|
+
after { FakeWeb.clean_registry }
|
23
|
+
subject(:connection) do
|
24
|
+
Bigcommerce::Connection.new(
|
25
|
+
:store_url => "https://store-12345.mybigcommerce.com",
|
26
|
+
:username => "test",
|
27
|
+
:api_key => "12345"
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
[:get, :post, :put, :delete].each do |http_method|
|
32
|
+
let(:path) { '/orders' }
|
33
|
+
describe "##{http_method}" do
|
34
|
+
eval "let(:http_method) { :#{http_method} }"
|
35
|
+
it_behaves_like "request method accepting optional params and headers"
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#request' do
|
39
|
+
context "when #{http_method.to_s.upcase} request" do
|
40
|
+
before do
|
41
|
+
http_class.stub(:new) { request }
|
42
|
+
Net::HTTP.stub(:new) { stub.as_null_object }
|
43
|
+
end
|
44
|
+
let(:http_class) { eval "Net::HTTP::#{http_method.to_s.gsub(/^(.)/) { $1.upcase }}" }
|
45
|
+
let(:args) { [http_method, path, options] }
|
46
|
+
let(:body) { nil }
|
47
|
+
let(:params) { {} }
|
48
|
+
let(:headers) { {} }
|
49
|
+
let(:options) { {:body => body, :params => params, :headers => headers}.reject { |k,v| v.nil? } }
|
50
|
+
let(:request) { stub.as_null_object }
|
51
|
+
|
52
|
+
it "requests path with API prefix" do
|
53
|
+
http_class.should_receive(:new).with("/api/v2#{path}")
|
54
|
+
connection.request(*args)
|
55
|
+
end
|
56
|
+
|
57
|
+
context "with querystring" do
|
58
|
+
let(:params) { {:foo => 'bar'} }
|
59
|
+
|
60
|
+
it "includes querystring" do
|
61
|
+
http_class.should_receive(:new).with("/api/v2#{path}?foo=bar")
|
62
|
+
connection.request(*args)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "with custom header" do
|
67
|
+
let(:headers) { {'Some-Header' => 'abc'} }
|
68
|
+
|
69
|
+
it "includes custom header" do
|
70
|
+
request.should_receive(:add_field).with('Some-Header', 'abc')
|
71
|
+
request.stub(:add_field) # ignoring other headers
|
72
|
+
connection.request(*args)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "#hash_to_params" do
|
80
|
+
# TODO: Consider using addressable gem; see <http://stackoverflow.com/a/803067/3528> for examples.
|
81
|
+
it "converts flat hashes to query strings" do
|
82
|
+
connection.hash_to_params({:a => 1, :b => 2}).should eql "a=1&b=2"
|
83
|
+
end
|
84
|
+
it "converts empty hashes to nil" do
|
85
|
+
connection.hash_to_params({}).should be_nil
|
86
|
+
end
|
87
|
+
it "leaves nil as nil" do
|
88
|
+
connection.hash_to_params(nil).should be_nil
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,84 +1,174 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: bigcommerce
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 5
|
10
|
-
version: 0.0.5
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
13
|
-
-
|
7
|
+
authors:
|
8
|
+
- Bigcommerce
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
12
|
+
date: 2013-01-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
22
23
|
prerelease: false
|
23
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
25
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: json
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
32
38
|
type: :runtime
|
33
|
-
|
34
|
-
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: ci_reporter
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: fakeweb
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: mocha
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: rake
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rspec
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '2.11'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ~>
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '2.11'
|
126
|
+
description: Enables Ruby applications to communicate with the Bigcommerce API V2.
|
35
127
|
email: dev-accounts@bigcommerce.com
|
36
128
|
executables: []
|
37
|
-
|
38
129
|
extensions: []
|
39
|
-
|
40
130
|
extra_rdoc_files: []
|
41
|
-
|
42
|
-
files:
|
131
|
+
files:
|
43
132
|
- LICENSE
|
44
133
|
- Rakefile
|
45
134
|
- README.md
|
46
135
|
- bigcommerce.gemspec
|
47
|
-
- lib/
|
48
|
-
- lib/bigcommerce/
|
49
|
-
- lib/bigcommerce.rb
|
136
|
+
- ./lib/big_commerce.rb
|
137
|
+
- ./lib/bigcommerce/api.rb
|
138
|
+
- ./lib/bigcommerce/connection.rb
|
139
|
+
- ./lib/bigcommerce/version.rb
|
140
|
+
- ./lib/bigcommerce.rb
|
141
|
+
- ./spec/models/api_spec.rb
|
142
|
+
- ./spec/models/connection_spec.rb
|
143
|
+
- ./spec/spec_helper.rb
|
144
|
+
- ./spec/support/fixture_helpers.rb
|
145
|
+
- spec/models/api_spec.rb
|
146
|
+
- spec/models/connection_spec.rb
|
50
147
|
homepage: http://github.com/bigcommerce/bigcommerce-api-ruby
|
51
148
|
licenses: []
|
52
|
-
|
53
149
|
post_install_message:
|
54
150
|
rdoc_options: []
|
55
|
-
|
56
|
-
require_paths:
|
151
|
+
require_paths:
|
57
152
|
- lib
|
58
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
153
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
154
|
none: false
|
60
|
-
requirements:
|
61
|
-
- -
|
62
|
-
- !ruby/object:Gem::Version
|
63
|
-
|
64
|
-
|
65
|
-
- 0
|
66
|
-
version: "0"
|
67
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ! '>='
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
160
|
none: false
|
69
|
-
requirements:
|
70
|
-
- -
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
|
73
|
-
segments:
|
74
|
-
- 0
|
75
|
-
version: "0"
|
161
|
+
requirements:
|
162
|
+
- - ! '>='
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
76
165
|
requirements: []
|
77
|
-
|
78
166
|
rubyforge_project:
|
79
|
-
rubygems_version: 1.8.
|
167
|
+
rubygems_version: 1.8.24
|
80
168
|
signing_key:
|
81
169
|
specification_version: 3
|
82
|
-
summary: Enables Ruby applications to communicate with the
|
83
|
-
test_files:
|
84
|
-
|
170
|
+
summary: Enables Ruby applications to communicate with the Bigcommerce API
|
171
|
+
test_files:
|
172
|
+
- spec/models/api_spec.rb
|
173
|
+
- spec/models/connection_spec.rb
|
174
|
+
has_rdoc: false
|