bigcommerce 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.md +88 -0
- data/Rakefile +1 -0
- data/bigcommerce.gemspec +13 -0
- data/lib/bigcommerce.rb +10 -0
- data/lib/bigcommerce/api.rb +63 -0
- data/lib/bigcommerce/connection.rb +57 -0
- data/lib/bigcommerce/version.rb +3 -0
- data/run.rb +11 -0
- metadata +88 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (C) BigCommerce, 2011.
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
6
|
+
in the Software without restriction, including without limitation the rights
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
9
|
+
furnished to do so, subject to the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be included in
|
12
|
+
all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
BigCommerce API V2 - Ruby Client
|
2
|
+
================================
|
3
|
+
|
4
|
+
This library provides a wrapper around the BigCommerce REST API for use within
|
5
|
+
Ruby apps or via the console.
|
6
|
+
|
7
|
+
Requirements
|
8
|
+
------------
|
9
|
+
|
10
|
+
- Ruby 1.8.7+
|
11
|
+
- Rubygems
|
12
|
+
- JSON
|
13
|
+
|
14
|
+
To connect to the API, you need the following credentials:
|
15
|
+
|
16
|
+
- Secure URL pointing to a BigCommerce store
|
17
|
+
- Username of an authorized admin user of the store
|
18
|
+
- API key for the user
|
19
|
+
|
20
|
+
A valid API key is required to authenticate requests. To grant API access for
|
21
|
+
user, go to Control Panel > Users > Edit User and make sure that the
|
22
|
+
'Enable the XML API?' checkbox is ticked.
|
23
|
+
|
24
|
+
Installation
|
25
|
+
------------
|
26
|
+
|
27
|
+
Download the lib folder and copy it to a path accessible within your app, or
|
28
|
+
install the package directly from Rubygems:
|
29
|
+
|
30
|
+
```
|
31
|
+
gem install bigcommerce
|
32
|
+
```
|
33
|
+
|
34
|
+
Configuration
|
35
|
+
-------------
|
36
|
+
|
37
|
+
To use the API client in your Ruby code, provide the required credentials as
|
38
|
+
follows:
|
39
|
+
|
40
|
+
```
|
41
|
+
require 'bigcommerce'
|
42
|
+
|
43
|
+
api = BigCommerce::Api.new({
|
44
|
+
:store_url => "https://store.mybigcommerce.com",
|
45
|
+
:username => "admin",
|
46
|
+
:api_key => "d81aada4c19c34d913e18f07fd7f36ca"
|
47
|
+
})
|
48
|
+
```
|
49
|
+
|
50
|
+
Connecting to the store
|
51
|
+
-----------------------
|
52
|
+
|
53
|
+
Ping the get_time method to check that your configuration is working and you
|
54
|
+
can connect successfully to the store:
|
55
|
+
|
56
|
+
```
|
57
|
+
ping = api.get_time
|
58
|
+
```
|
59
|
+
|
60
|
+
Usage
|
61
|
+
-----
|
62
|
+
|
63
|
+
The API object acts as a gateway to all top level resources in the V2 API.
|
64
|
+
|
65
|
+
```
|
66
|
+
$ irb
|
67
|
+
>
|
68
|
+
> api = BigCommerce::Api.new(...)
|
69
|
+
>
|
70
|
+
> api.get_products.each { |product| puts product.name }
|
71
|
+
>
|
72
|
+
> api.get_customers.each { |customer| puts customer.email }
|
73
|
+
>
|
74
|
+
> puts api.get_orders_count
|
75
|
+
>
|
76
|
+
> category = api.get_category(11)
|
77
|
+
> category.name = "Laptops"
|
78
|
+
> category.update
|
79
|
+
>
|
80
|
+
> brand = BigCommerce::Api::Brand.new
|
81
|
+
> brand.name = "Samsung"
|
82
|
+
> brand.create
|
83
|
+
>
|
84
|
+
> option = api.get_option(22)
|
85
|
+
> option.delete
|
86
|
+
>
|
87
|
+
```
|
88
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
#require "bundler/gem_tasks"
|
data/bigcommerce.gemspec
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "bigcommerce"
|
3
|
+
s.version = "0.0.1"
|
4
|
+
s.date = "2011-09-12"
|
5
|
+
s.summary = "Enables Ruby applications to communicate with the BigCommerce API"
|
6
|
+
s.email = "dev-accounts@bigcommerce.com"
|
7
|
+
s.homepage = "http://github.com/tlconnor/xero_gateway"
|
8
|
+
s.description = "Enables Ruby applications to communicate with the BigCommerce API"
|
9
|
+
s.has_rdoc = false
|
10
|
+
s.authors = ["BigCommerce"]
|
11
|
+
s.files = ["LICENSE", "Rakefile", "README.md", "bigcommerce.gemspec"] + Dir['**/*.rb'] + Dir['**/*.crt']
|
12
|
+
s.add_dependency('json')
|
13
|
+
end
|
data/lib/bigcommerce.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require "cgi"
|
2
|
+
require "uri"
|
3
|
+
require "net/https"
|
4
|
+
|
5
|
+
require "rubygems"
|
6
|
+
require "json"
|
7
|
+
|
8
|
+
require File.join(File.dirname(__FILE__), 'bigcommerce', 'version')
|
9
|
+
require File.join(File.dirname(__FILE__), 'bigcommerce', 'api')
|
10
|
+
require File.join(File.dirname(__FILE__), 'bigcommerce', 'connection')
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module BigCommerce
|
2
|
+
class Api
|
3
|
+
|
4
|
+
def initialize(configuration)
|
5
|
+
@connection = Connection.new(configuration)
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_time
|
9
|
+
@connection.get '/time'
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_products
|
13
|
+
@connection.get '/products'
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_product(id)
|
17
|
+
@connection.get '/products/' + id
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_categories
|
21
|
+
@connection.get '/categories'
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_category(id)
|
25
|
+
@connection.get '/categories/' + id
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_orders
|
29
|
+
@connection.get('/orders')
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_orders_by_date(date)
|
33
|
+
@connection.get '/orders?min_date_created=' + CGI::escape(date)
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_orders_count
|
37
|
+
get_count @connection.get '/orders/count'
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_order(id)
|
41
|
+
@connection.get '/orders/' + id
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_order_products(id)
|
45
|
+
@connection.get '/orders/' + id + '/products'
|
46
|
+
end
|
47
|
+
|
48
|
+
def get_customers
|
49
|
+
@connection.get '/customers'
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_customer(id)
|
53
|
+
@connection.get '/customers/' + id
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def get_count(result)
|
59
|
+
result["count"]
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module BigCommerce
|
2
|
+
class Connection
|
3
|
+
|
4
|
+
def initialize(configuration)
|
5
|
+
@configuration = configuration
|
6
|
+
end
|
7
|
+
|
8
|
+
def get(path)
|
9
|
+
request(:get, path)
|
10
|
+
end
|
11
|
+
|
12
|
+
def post(path)
|
13
|
+
request(:post, path)
|
14
|
+
end
|
15
|
+
|
16
|
+
def put(path)
|
17
|
+
request(:put, path)
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete(path)
|
21
|
+
request(:delete, path)
|
22
|
+
end
|
23
|
+
|
24
|
+
def request(method, path, body = nil, params = {})
|
25
|
+
|
26
|
+
url = @configuration[:store_url] + '/api/v2' + path
|
27
|
+
|
28
|
+
uri = URI.parse(url)
|
29
|
+
|
30
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
31
|
+
|
32
|
+
request = case method
|
33
|
+
when :get then Net::HTTP::Get.new(uri.request_uri)
|
34
|
+
when :post then Net::HTTP::Post.new(uri.request_uri)
|
35
|
+
when :put then Net::HTTP::Put.new(uri.request_uri)
|
36
|
+
when :delete then Net::HTTP::Delete.new(uri.request_uri)
|
37
|
+
end
|
38
|
+
|
39
|
+
request.basic_auth(@configuration[:username], @configuration[:api_key])
|
40
|
+
request.add_field 'Accept', 'application/json'
|
41
|
+
request.add_field 'Content-Type', 'application/json'
|
42
|
+
|
43
|
+
response = http.request(request)
|
44
|
+
|
45
|
+
return case response
|
46
|
+
when Net::HTTPSuccess, Net::HTTPRedirection
|
47
|
+
JSON.parse(response.body || "{}")
|
48
|
+
else false
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
class HttpError < Exception
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
data/run.rb
ADDED
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bigcommerce
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- BigCommerce
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-09-12 00:00:00 +10:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: json
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description: Enables Ruby applications to communicate with the BigCommerce API
|
36
|
+
email: dev-accounts@bigcommerce.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- LICENSE
|
45
|
+
- Rakefile
|
46
|
+
- README.md
|
47
|
+
- bigcommerce.gemspec
|
48
|
+
- lib/bigcommerce/version.rb
|
49
|
+
- lib/bigcommerce/api.rb
|
50
|
+
- lib/bigcommerce/connection.rb
|
51
|
+
- lib/bigcommerce.rb
|
52
|
+
- run.rb
|
53
|
+
has_rdoc: true
|
54
|
+
homepage: http://github.com/tlconnor/xero_gateway
|
55
|
+
licenses: []
|
56
|
+
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
hash: 3
|
68
|
+
segments:
|
69
|
+
- 0
|
70
|
+
version: "0"
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 3
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
80
|
+
requirements: []
|
81
|
+
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 1.3.7
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: Enables Ruby applications to communicate with the BigCommerce API
|
87
|
+
test_files: []
|
88
|
+
|