Skip to content

Commit

Permalink
Support OAuth authentication for the Bigcommerce API.
Browse files Browse the repository at this point in the history
This code is pulled in the mechatama/bigcommerce-api-ruby repo on the
oauth branch.

- Updates to the README
- OAuth support
- Bump minor version
- Remove unnecessary code
  • Loading branch information
pedelman committed Feb 4, 2015
1 parent c1248b6 commit a6105d2
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 138 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -15,3 +15,5 @@

# Rspec
/tmp

.DS_Store
6 changes: 1 addition & 5 deletions .travis.yml
@@ -1,14 +1,10 @@
language: ruby
rvm:
- 2.1.0
- 2.1.5
- 2.0.0
- 1.9.3
- jruby-19mode
- rbx-2.2.3 # Travis CI build fails with 2.2.4
- rbx # Travis CI build fails with 2.2.4
env: API_URL=https://store-vnh06c71.mybigcommerce.com API_USER=admin API_PASS=123456

matrix:
fast_finish: true
allow_failures:
- rvm: rbx # Travis CI build fails with 2.2.4
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,4 +1,4 @@
Copyright (C) Bigcommerce, 2011.
Copyright (C) Bigcommerce, 2015.
All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
125 changes: 52 additions & 73 deletions README.md
@@ -1,5 +1,4 @@
Bigcommerce API V2 - Ruby Client
================================
# Bigcommerce API V2 - Ruby Client

[![Gem Version](https://badge.fury.io/rb/bigcommerce.png)](https://rubygems.org/gems/bigcommerce)
[![Build Status](https://travis-ci.org/bigcommerce/bigcommerce-api-ruby.png?branch=master)](https://travis-ci.org/bigcommerce/bigcommerce-api-ruby)
Expand All @@ -10,121 +9,101 @@ Bigcommerce API V2 - Ruby Client
This library provides a wrapper around the Bigcommerce REST API for use within
Ruby apps or via the console.

Note
----
### Note

If you find anything that is missing or needs clean up, please feel free to fork
it and submit a changes with your pull request.

Requirements
------------
## Requirements

- Ruby 1.9+

To connect to the API, you need the following credentials:

For the OAuth API:

- Create and register an app at [developer.bigcommerce.com](https://developer.bigcommerce.com).
- Have a callback URL defined
- Prepare the `client_id` credential

For the Legacy API:

- Secure URL pointing to a Bigcommerce store
- Username of an authorized admin user of the store
- API key for the user

A valid API key is required to authenticate requests. To grant API access for a
user, go to Control Panel > Users > Edit User and make sure that the
'Enable API access?' checkbox is ticked.
A valid API key is required to authenticate requests. To grant API access for a user, go to Control Panel > Users > Edit User and make sure that the 'Enable API access?' checkbox is ticked.

Installation
------------
## Installation

Download the lib folder and copy it to a path accessible within your app, or
install the package directly from Rubygems:

```
```sh
gem install bigcommerce
```

Note that the RubyGems version of this gem might be outdated. You can install the
gem directly from this repo. If you are using Rails, you can point your Gemfile
to this git repo directly or do a local install of the gem by -
## Configuration

```
rake build
gem install pkg/bigcommerce-*.gem
```
#### OAuth Authentication

Configuration
-------------
In order to create a new Bigcommerce application, please visit [developer.bigcommerce.com](https://developer.bigcommerce.com). Its free to sign up and only takes a moment. Once you have created your app, you can get a `client_id`.

To use the API client in your Ruby code, provide the required credentials as
follows:

```
```rb
require 'bigcommerce'

api = Bigcommerce::Api.new({
:store_url => "https://store.mybigcommerce.com",
:username => "admin",
:api_key => "d81aada4c19c34d913e18f07fd7f36ca"
:store_hash => 'STORE_HASH',
:client_id => 'CLIENT_ID',
:access_token => 'ACCESS_TOKEN'
})
```

If you want to enable SSL certificates -

```
require 'bigcommerce'
api = Bigcommerce::Api.new({
:store_url => "https://store.mybigcommerce.com",
:username => "admin",
:api_key => "d81aada4c19c34d913e18f07fd7f36ca"
:ssl_client_cert => OpenSSL::X509::Certificate.new(File.read("cert.pem")),
:ssl_client_key => OpenSSL::PKey::RSA.new(File.read("key.pem"), "passphrase, if any"),
:ssl_ca_file => "ca_certificate.pem",
:verify_ssl => OpenSSL::SSL::VERIFY_PEER
})
```
Remember that the fields `:ssl_client_cert`, `:ssl_client_key`, `:ssl_ca_file`
and `:verify_ssl` are all required when enabling SSL certificates.

Connecting to the store
-----------------------

Ping the time method to check that your configuration is working and you
can connect successfully to the store:
__NOTE:__ You do not need extra SSL certificates when connecting to the OAuth version of the api.

```
ping = api.time
```
#### Legacy Credentials

Usage
-----
To use the API client with the legacy credentials you can visit the main store page and under the "Setup & Tools" dropdown, you will see a link for the legacy API credentials.

The API object acts as a gateway to all top level resources in the V2 API.
```rb
require 'bigcommerce'

Fetch Data
api = Bigcommerce::Api.new({
:store_url => "https://store.mybigcommerce.com",
:username => "username",
:api_key => "api_key"
})
```
orders = api.orders
orders = api.orders({:min_id=>100,:max_id=>101})
orders = api.orders(:is_deleted => true)

products = api.products
products = api.products(:description=>"iphone", :condition=>"New")
You can also enable SSL for the Legacy API.

options = api.options
options = api.options(:type=>"MT")
...
```rb
require 'bigcommerce'

api = Bigcommerce::Api.new({
:store_url => "https://store.mybigcommerce.com",
:username => "username",
:api_key => "api_key",
:ssl_client_cert => OpenSSL::X509::Certificate.new(File.read("cert.pem")),
:ssl_client_key => OpenSSL::PKey::RSA.new(File.read("key.pem"), "passphrase, if any"),
:ssl_ca_file => "ca_certificate.pem",
:verify_ssl => OpenSSL::SSL::VERIFY_PEER
})
```
Create Data
```
api.create_products({:name => "Spiderman - The best return",:price => 9.99,:categories => [17],:type =>"physical",:availability => "available", :weight => 1})
api.update_products(31,{:name => "marvel comics spiderman",:sku => "marvel-spidey-1", :inventory_tracking => "simple", :inventory_level => 500})
Remember that the fields `:ssl_client_cert`, `:ssl_client_key`, `:ssl_ca_file`
and `:verify_ssl` are all required when enabling SSL certificates.

api.update_orders(101,{:status_id => 12, :is_deleted => true})
## Connecting to the store

```
Update Data
Once you have authenticated with the OAuth or Legacy credentials, ping the time method to check that your configuration is working and you can connect successfully to the store:

```rb
ping = api.time()
```
api.update_products(31,{:name => "marvel comics spiderman",:sku => "marvel-spidey-1", :inventory_tracking => "simple", :inventory_level => 500})

api.update_optionsets(13,{:name => "Marvel toys"})
## Reference

```
For full reference about the resources and supported endpoints, please see [developer.bigcommerce.com](https://developer.bigcommerce.com).
13 changes: 7 additions & 6 deletions bigcommerce.gemspec
Expand Up @@ -3,14 +3,15 @@

Gem::Specification.new do |s|
s.name = "bigcommerce"
s.version = "0.9.0"
s.version = "0.10.0"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Mark Rickerby", "Rob Howard", "Saranyan Vigraham", "Sasha Gerrand"]
s.date = "2013-11-18"
s.date = "2015-01-27"
s.description = "Enables Ruby applications to communicate with the Bigcommerce API V2."
s.license = 'MIT'
s.email = ["mark.rickerby@bigcommerce.com", "rob.howard@bigcommerce.com", "saranyan.vigraham@bigcommerce.com", "sasha.gerrand@bigcommerce.com"]
s.files = ["LICENSE", "Rakefile", "README.md", "bigcommerce.gemspec", "./lib/big_commerce.rb", "./lib/bigcommerce/api.rb", "./lib/bigcommerce/connection.rb", "./lib/bigcommerce/version.rb", "./lib/bigcommerce.rb", "./spec/big_commerce_spec.rb", "./spec/integration/orders_spec.rb", "./spec/spec_helper.rb", "./spec/support/integration_context.rb", "./spec/support/mock_api_context.rb", "./spec/unit/api_request_spec.rb", "./spec/unit/api_spec.rb", "./spec/unit/connection_spec.rb", "./spec/unit/date_time_spec.rb", "./spec/unit/version_spec.rb", "spec/big_commerce_spec.rb", "spec/integration/orders_spec.rb", "spec/unit/api_request_spec.rb", "spec/unit/api_spec.rb", "spec/unit/connection_spec.rb", "spec/unit/date_time_spec.rb", "spec/unit/version_spec.rb"]
s.files = ["LICENSE", "Rakefile", "README.md", "bigcommerce.gemspec", "./lib/big_commerce.rb", "./lib/bigcommerce/api.rb", "./lib/bigcommerce/connection.rb", "./lib/bigcommerce/version.rb", "./lib/bigcommerce/resource.rb", "./lib/bigcommerce/product.rb", "./lib/bigcommerce.rb", "./spec/big_commerce_spec.rb", "./spec/integration/orders_spec.rb", "./spec/spec_helper.rb", "./spec/support/integration_context.rb", "./spec/support/mock_api_context.rb", "./spec/unit/api_request_spec.rb", "./spec/unit/api_spec.rb", "./spec/unit/connection_spec.rb", "./spec/unit/date_time_spec.rb", "./spec/unit/version_spec.rb", "spec/big_commerce_spec.rb", "spec/integration/orders_spec.rb", "spec/unit/api_request_spec.rb", "spec/unit/api_spec.rb", "spec/unit/connection_spec.rb", "spec/unit/date_time_spec.rb", "spec/unit/version_spec.rb"]
s.homepage = "http://github.com/bigcommerce/bigcommerce-api-ruby"
s.require_paths = ["lib"]
s.rubygems_version = "2.1.11"
Expand All @@ -25,7 +26,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency(%q<json>, [">= 0"])
s.add_runtime_dependency(%q<rest-client>, [">= 0"])
s.add_development_dependency(%q<coveralls>, [">= 0"])
s.add_development_dependency(%q<ci_reporter>, [">= 0"])
s.add_development_dependency(%q<ci_reporter_rspec>, [">= 0"])
s.add_development_dependency(%q<mocha>, [">= 0"])
s.add_development_dependency(%q<rake>, [">= 0"])
s.add_development_dependency(%q<rspec>, ["~> 2.11"])
Expand All @@ -36,7 +37,7 @@ Gem::Specification.new do |s|
s.add_dependency(%q<json>, [">= 0"])
s.add_dependency(%q<rest-client>, [">= 0"])
s.add_dependency(%q<coveralls>, [">= 0"])
s.add_dependency(%q<ci_reporter>, [">= 0"])
s.add_dependency(%q<ci_reporter_rspec>, [">= 0"])
s.add_dependency(%q<mocha>, [">= 0"])
s.add_dependency(%q<rake>, [">= 0"])
s.add_dependency(%q<rspec>, ["~> 2.11"])
Expand All @@ -48,7 +49,7 @@ Gem::Specification.new do |s|
s.add_dependency(%q<json>, [">= 0"])
s.add_dependency(%q<rest-client>, [">= 0"])
s.add_dependency(%q<coveralls>, [">= 0"])
s.add_dependency(%q<ci_reporter>, [">= 0"])
s.add_dependency(%q<ci_reporter_rspec>, [">= 0"])
s.add_dependency(%q<mocha>, [">= 0"])
s.add_dependency(%q<rake>, [">= 0"])
s.add_dependency(%q<rspec>, ["~> 2.11"])
Expand Down
29 changes: 5 additions & 24 deletions lib/bigcommerce/api.rb
Expand Up @@ -42,6 +42,10 @@ def time
@connection.get '/time'
end

def store_information
@connection.get '/store'
end

def brands(options={})
@connection.get("/brands", options)
end
Expand Down Expand Up @@ -290,10 +294,7 @@ def orderstatus(id,options={})
end

def products(options={})
if (!options["resource_class"])
options["resource_class"] = Product
end
collection("/products", options)
@connection.get("/products", options)
end

def products_count
Expand Down Expand Up @@ -376,10 +377,6 @@ def create_product_images(product_id, options={})
@connection.post("/products/#{product_id}/images", options)
end

def products_images(options={})
@connection.get("/products/images", options)
end

def create_products_images(options={})
@connection.post("/products/images", options)
end
Expand All @@ -392,10 +389,6 @@ def update_products_image(product_id,image_id,options={})
@connection.put("/products/#{product_id}/images/#{image_id}", options)
end

def products_customfields(options={})
@connection.get("/products/options", options)
end

def product_options(product_id, options={})
@connection.get("/products/#{product_id}/options", options)
end
Expand All @@ -404,10 +397,6 @@ def products_option(product_id,option_id, options={})
@connection.get("/products/#{product_id}/options/#{option_id}", options)
end

def products_rules(options={})
@connection.get("/products/rules", options)
end

def product_rules(product_id, options={})
@connection.get("/products/#{product_id}/rules", options)
end
Expand All @@ -424,10 +413,6 @@ def update_products_rule(product_id, rule_id, options={})
@connection.put("/products/#{product_id}/rules/#{rule_id}", options)
end

def products_skus(options={})
@connection.get("/products/skus", options)
end

def product_skus(product_id, options={})
@connection.get("/products/#{product_id}/skus", options)
end
Expand All @@ -444,10 +429,6 @@ def update_products_sku(product_id, sku_id, options={})
@connection.put("/products/#{product_id}/skus/#{sku_id}", options)
end

def products_videos(options={})
@connection.get("/products/videos", options)
end

def product_videos(product_id, options={})
@connection.get("/products/#{product_id}/videos", options)
end
Expand Down

0 comments on commit a6105d2

Please sign in to comment.