Giter Site home page Giter Site logo

bigcommerce / bigcommerce-api-ruby Goto Github PK

View Code? Open in Web Editor NEW
78.0 33.0 124.0 338 KB

Connect Ruby applications with the Bigcommerce Platform

Home Page: https://developer.bigcommerce.com

License: MIT License

Ruby 99.80% Shell 0.20%
ruby bigcommerce oauth api-client

bigcommerce-api-ruby's Introduction

BigCommerce API Ruby

Gem Version CircleCI Test Coverage Maintainability

This is the official BigCommerce API client to support our Stores API. You can find more information about becoming a BigCommerce developer here: developer.bigcommerce.com.

Installation

BigCommerce is available on RubyGems.

gem install bigcommerce

You can also add it to your Gemfile.

gem 'bigcommerce', '~> 1.0'

Requirements

  • Ruby 2.7.5 or newer (Ruby 3.0+ is preferred)

Getting Started

To make requests to our API, you must register as a developer and have your credentials ready.

Also very important: For the OAuth authentication mechanism, the resources to which you have acccess depend on the scopes that the merchant has granted to your application. For more information about Store API scopes, see: OAuth Scopes.

Authentication

We currently have two different authentication schemes that you can select, depending on your use case.

OAuth

OAuth apps can be submitted to BigCommerce App Store, allowing other merchants to install these apps in their BigCommerce stores.

More Information

Basic Authentication (Legacy)

To develop a custom integration for one store, your app needs to use Basic Authentication.

More Information

Configuration

To authenticate your API client, you will need to configure the client like the following examples.

OAuth App

  • client_id: Obtained from the on the BigCommerce Developer Portal's "My Apps" section.
  • access_token: Obtained after a token exchange in the auth callback.
  • store_hash: Also obtained after the token exchange.
Bigcommerce.configure do |config|
  config.store_hash = ENV['BC_STORE_HASH']
  config.client_id = ENV['BC_CLIENT_ID']
  config.access_token = ENV['BC_ACCESS_TOKEN']
end

Basic Authentication (Legacy)

To get all the basic auth credentials, simply visit your store admin page, and navigate to the Advanced Settings > Legacy API Settings. Once there, you can create a new legacy API account on which to authenticate.

Bigcommerce.configure do |config|
  config.auth = 'legacy'
  config.url = ENV['BC_API_ENDPOINT_LEGACY']
  config.username = ENV['BC_USERNAME']
  config.api_key = ENV['BC_API_KEY']
end

SSL Configuration

If you are using your own, self-signed, certificate, you can pass SSL options to Faraday. This is not required, but might be useful in special edge cases.

Bigcommerce.configure do |config|
  config.auth = 'legacy'
  config.url = 'https://api_path.com'
  config.username = 'username'
  config.api_key = 'api_key'
  config.ssl = {
    # Faraday options here
  }
end

For more information about configuring SSL with Faraday, please see the following:

Customer Login API

If you want to generate tokens for storefront login using the Customer Login API, you need to configure your app's client secret.

  • store_hash: The store hash of the store you are operating against.
  • client_id: Obtained from the on the BigCommerce Developer Portal's "My Apps" section.
  • client_secret: Obtained from the on the BigCommerce Developer Portal's "My Apps" section.
Bigcommerce.configure do |config|
  config.store_hash = ENV['BC_STORE_HASH']
  config.client_id = ENV['BC_CLIENT_ID']
  config.client_secret = ENV['BC_CLIENT_SECRET']
end

Usage

For full examples of using the API client, please see the examples folder and refer to BigCommerce's developer documentation.

Example:

# Configure the client to talk to a given store
Bigcommerce.configure do |config|
  config.store_hash = ENV['BC_STORE_HASH']
  config.client_id = ENV['BC_CLIENT_ID']
  config.access_token = ENV['BC_ACCESS_TOKEN']
end

# Make an API request for a given resource
Bigcommerce::System.time
=> #<Bigcommerce::System time=1466801314>

Thread Safety

The Bigcommerce.configure method is NOT thread-safe. This mechanism is designed for applications or CLIs (command-line interfaces) where thread safety is not a concern. If you need to guarantee thread safety, we support this alternative mechanism to make thread-safe API requests:

Rather then setting up a single connection for all API requests, construct a new connection for each thread. If you can ensure that each of these connections is stored in a thread-safe manner, you can pass the connection as you query the resource.

This connection is nothing more than a Faraday::Connection โ€“ so if you want to write your own, or to use your own adapters, you can feel free. Please refer to this gem's connection class for more details.

OAuth
connection = Bigcommerce::Connection.build(
  Bigcommerce::Config.new(
    store_hash: ENV['BC_STORE_HASH'],
    client_id: ENV['BC_CLIENT_ID'],
    access_token: ENV['BC_ACCESS_TOKEN']
  )
)
=> #<Faraday::Connection:0x007fbf95068978 ... >>

Bigcommerce::System.time(connection: connection)
=> #<Bigcommerce::System time=1466546702>

Bigcommerce::System.raw_request(:get, 'time', connection: connection)
=> #<Faraday::Response:0x007fd4a4063170 ... >>
Basic Auth
connection_legacy = Bigcommerce::Connection.build(
  Bigcommerce::Config.new(
    auth: 'legacy',
    url: ENV['BC_API_ENDPOINT_LEGACY'],
    username: ENV['BC_USERNAME'],
    api_key: ENV['BC_API_KEY']
  )
)
=> #<Faraday::Connection:0x007fbf95068978 ... >>

Bigcommerce::System.time(connection: connection_legacy)
=> #<Bigcommerce::System time=1466546702>

Bigcommerce::System.raw_request(:get, 'time', connection: connection_legacy)
=> #<Faraday::Response:0x007fd4a4063170 ... >>

Contributing

See CONTRIBUTING.md

License

See LICENSE.md

bigcommerce-api-ruby's People

Contributors

adambilsing avatar alexnesbitt avatar bc-chaz avatar bookernath avatar bradx3 avatar cwalsh avatar damncabbage avatar gregory avatar imerica avatar j05h avatar jayelkaake avatar johnhebron avatar maetl avatar mattolson avatar mikelarkin avatar pedelman avatar pospischil avatar ranjeetkumarkanaily avatar saranyan avatar saurabh-g avatar scottburton11 avatar sebastianszturo avatar sgerrand avatar splittingred avatar squish avatar timlkelly avatar turnrye avatar winfred avatar xyzjace avatar zubin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bigcommerce-api-ruby's Issues

filtering optionsets_options

When I try to filter for optionsets options via something like:

api.get_optionsets_options(display_name: option_name)

I get all optionsets options. Filtering doesn't actually seem to work.

Failed to parse Bigcommerce response

When I try to get shipping_addresses for each order, I get an error:
....gems/bigcommerce-0.8.1/lib/bigcommerce/connection.rb:91:in `rescue in request': Failed to parse Bigcommerce response: A JSON text must at least contain two octets! (RuntimeError)

Code:

@api = Bigcommerce::Api.new({
store_url: @api_config['store_url'],
username: @api_config['username'],
api_key: @api_config['api_key']
})

orders = @api.get_orders
orders.each do |order|
order['shipping_addresses']['data'] = @api.connection.get(order['shipping_addresses']['resource'])
end

OAuth2 Support

I realised that BigCommerce deprecated HTTP Basic authentication and upgraded API to use OAuth2. Is there any plan to upgrade the gem to give OAuth2 support?

Viewing price for SKU

Does the gem support the price field for SKUs? I can't seem to see it in the response. Perhaps I'm missing something obvious. Apologies if that is the case.

Problem:
I see that price is a property of SKU, however I set a price on the BigCommerce web dashboard, and cannot see it when I use the gem to query the SKU.

Environment

  • Ruby 1.9.3p551
  • Rails 3.2.15
  • Gem: bigcommerce 1.0.0.beta

Steps to reproduce
SKU on BigCommerce (saved changes):

Gem Query Response:

As you can see, the cost_price and custom UPC came over, but I do not see any price property in the returned Bigcommerce Sku Object

The build for Rubinius is failing

The build for Rubinius is failing with the following errors:

Failures:
  1) /api/v2/orders gets the orders collection
     Failure/Error: orders = api.orders
     NoMethodError:
       private method `load' called on Psych (Module)
     # kernel/delta/kernel.rb:78:in `load (method_missing)'
     # kernel/bootstrap/proc.rb:20:in `call'
     # kernel/bootstrap/proc.rb:20:in `call'
     # kernel/common/enumerable.rb:418:in `find'
     # kernel/bootstrap/array.rb:66:in `each'
     # kernel/common/enumerable.rb:416:in `detect (find)'
     # ./lib/bigcommerce/connection.rb:81:in `request'
     # ./lib/bigcommerce/connection.rb:46:in `get'
     # ./lib/bigcommerce/api.rb:222:in `orders'
     # ./spec/integration/orders_spec.rb:7:in `__script__'
     # kernel/common/eval.rb:43:in `instance_eval'
     # kernel/bootstrap/array.rb:87:in `map'
     # kernel/bootstrap/array.rb:87:in `map'
     # kernel/bootstrap/proc.rb:20:in `call'
     # kernel/loader.rb:710:in `run_at_exits'
     # kernel/loader.rb:730:in `epilogue'
     # kernel/loader.rb:866:in `main'
  2) /api/v2/orders filters orders by date
     Failure/Error: orders = api.orders_by_date('2013-03-01')
     NoMethodError:
       private method `load' called on Psych (Module)
     # kernel/delta/kernel.rb:78:in `load (method_missing)'
     # kernel/bootstrap/proc.rb:20:in `call'
     # kernel/bootstrap/proc.rb:20:in `call'
     # kernel/common/enumerable.rb:418:in `find'
     # kernel/bootstrap/array.rb:66:in `each'
     # kernel/common/enumerable.rb:416:in `detect (find)'
     # ./lib/bigcommerce/connection.rb:81:in `request'
     # ./lib/bigcommerce/connection.rb:46:in `get'
     # ./lib/bigcommerce/api.rb:229:in `orders_by_date'
     # ./spec/integration/orders_spec.rb:13:in `__script__'
     # kernel/common/eval.rb:43:in `instance_eval'
     # kernel/bootstrap/array.rb:87:in `map'
     # kernel/bootstrap/array.rb:87:in `map'
     # kernel/bootstrap/proc.rb:20:in `call'
     # kernel/loader.rb:710:in `run_at_exits'
     # kernel/loader.rb:730:in `epilogue'
     # kernel/loader.rb:866:in `main'
Finished in 1.1 seconds
20 examples, 2 failures
Failed examples:
rspec ./spec/integration/orders_spec.rb:6 # /api/v2/orders gets the orders collection
rspec ./spec/integration/orders_spec.rb:12 # /api/v2/orders filters orders by date
Failures:
  1) /api/v2/orders gets the orders collection
     Failure/Error: orders = api.orders
     NoMethodError:
       private method `load' called on Psych (Module)
     # kernel/delta/kernel.rb:78:in `load (method_missing)'
     # kernel/bootstrap/proc.rb:20:in `call'
     # kernel/bootstrap/proc.rb:20:in `call'
     # kernel/common/enumerable.rb:418:in `find'
     # kernel/bootstrap/array.rb:66:in `each'
     # kernel/common/enumerable.rb:416:in `detect (find)'
     # ./lib/bigcommerce/connection.rb:81:in `request'
     # ./lib/bigcommerce/connection.rb:46:in `get'
     # ./lib/bigcommerce/api.rb:222:in `orders'
     # ./spec/integration/orders_spec.rb:7:in `__script__'
     # kernel/common/eval.rb:43:in `instance_eval'
     # kernel/bootstrap/array.rb:87:in `map'
     # kernel/bootstrap/array.rb:87:in `map'
     # kernel/bootstrap/proc.rb:20:in `call'
     # kernel/loader.rb:710:in `run_at_exits'
     # kernel/loader.rb:730:in `epilogue'
     # kernel/loader.rb:866:in `main'
  2) /api/v2/orders filters orders by date
     Failure/Error: orders = api.orders_by_date('2013-03-01')
     NoMethodError:
       private method `load' called on Psych (Module)
     # kernel/delta/kernel.rb:78:in `load (method_missing)'
     # kernel/bootstrap/proc.rb:20:in `call'
     # kernel/bootstrap/proc.rb:20:in `call'
     # kernel/common/enumerable.rb:418:in `find'
     # kernel/bootstrap/array.rb:66:in `each'
     # kernel/common/enumerable.rb:416:in `detect (find)'
     # ./lib/bigcommerce/connection.rb:81:in `request'
     # ./lib/bigcommerce/connection.rb:46:in `get'
     # ./lib/bigcommerce/api.rb:229:in `orders_by_date'
     # ./spec/integration/orders_spec.rb:13:in `__script__'
     # kernel/common/eval.rb:43:in `instance_eval'
     # kernel/bootstrap/array.rb:87:in `map'
     # kernel/bootstrap/array.rb:87:in `map'
     # kernel/bootstrap/proc.rb:20:in `call'
     # kernel/loader.rb:710:in `run_at_exits'
     # kernel/loader.rb:730:in `epilogue'
     # kernel/loader.rb:866:in `main'

License missing from gemspec

RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.

via e.g.

spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']

Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can imagine, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.

There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!

Appendix:

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies

p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post about this project for more information.

bigcommerce/api.rb needs to require date

Attempting to use Bigcommerce::API.get_orders_by_date results in an error if you haven't loaded date.

In irb:

require 'bigcommerce'
api = Bigcommerce::Api.new({
    :store_url => '#', 
    :username => '#', 
    :api_key => '#'
})
api.get_orders_by_date('2012-1-1')

results in:

NameError: uninitialized constant Bigcommerce::Api::DateTime
from /Users/chris/.rvm/gems/ruby-1.9.3-p392/gems/bigcommerce-0.8.4/lib/bigcommerce/api.rb:222:in `get_orders_by_date'

requiring date resolves this issue.

Bug when configuring OAuth

I feel like the thread safe methods weren't tested very well with OAuth.

Im getting this error:

NoMethodError: undefined method `each' for nil:NilClass
	from /Users/achadee/.rvm/gems/ruby-2.1.2/gems/faraday-0.12.0.1/lib/faraday/options.rb:49:in `merge!'
	from /Users/achadee/.rvm/gems/ruby-2.1.2/gems/faraday-0.12.0.1/lib/faraday/options.rb:60:in `merge'
	from /Users/achadee/.rvm/gems/ruby-2.1.2/gems/faraday-0.12.0.1/lib/faraday/options.rb:52:in `block in merge!'
	from /Users/achadee/.rvm/gems/ruby-2.1.2/gems/faraday-0.12.0.1/lib/faraday/options.rb:49:in `each'
	from /Users/achadee/.rvm/gems/ruby-2.1.2/gems/faraday-0.12.0.1/lib/faraday/options.rb:49:in `merge!'
	from /Users/achadee/.rvm/gems/ruby-2.1.2/gems/faraday-0.12.0.1/lib/faraday/options.rb:60:in `merge'
	from /Users/achadee/.rvm/gems/ruby-2.1.2/gems/faraday-0.12.0.1/lib/faraday/connection.rb:61:in `initialize'
	from /Users/achadee/.rvm/gems/ruby-2.1.2/gems/faraday-0.12.0.1/lib/faraday.rb:67:in `new'
	from /Users/achadee/.rvm/gems/ruby-2.1.2/gems/faraday-0.12.0.1/lib/faraday.rb:67:in `new'
	from /Users/achadee/.rvm/gems/ruby-2.1.2/gems/bigcommerce-1.0.0/lib/bigcommerce/connection.rb:11:in `build'
	from /Users/achadee/Projects/anthq/gems/ant_bigcommerce/lib/ant_bigcommerce/connection.rb:66:in `setup'
	from (irb):1
	from bin/console:15:in `<main>'

Which is obviously being caused by this line:

https://github.com/bigcommerce/bigcommerce-api-ruby/blob/v1.0.0/lib/bigcommerce/connection.rb#L10

Because the ssl_options are being set to nil and its trying to iterate over the keys.

I ran the Faraday method manually and set the ssl_options to an empty hash {} instead of a nil and it worked first time. Surely others are experiencing this issue?

my code:

      connection = ::Bigcommerce::Connection.build(
        ::Bigcommerce::Config.new(
          store_hash: credentials[:context],
          client_id: ENV['BC_CLIENT_ID'],
          access_token: credentials[:access_token],
        )
      )

About time for a release?

Hey guys,

Thanks for providing a ruby client, but it's been about 9 months since the last release and there's at least one fix our code depends on since the last release (1.0.0.beta in march '15) which means we have to specify the gem by SHA in all our Gemfiles and can't list the specific version as an internal gem dependency (SHAs work for Gemfiles, not gemspecs).

Since you recommend that developers upgrade to the beta version in the README and it's been out for awhile and presumably widely in use in production, seems like that roughly fits the criteria for bumping it to 1.0.0 and beyond?

All 1.0.0 means is that further changes will respect major, minor, patchlevel version adjustments dependent on changes to the public API, which would be a useful thing to depend on for us and I'm sure others would appreciate it as well.

Thanks,
John Wilkinson
ReferralCandy

Add support for webhooks

The SDK needs to be able to handle a different endpoint, methods etc added to support webhooks

Latest version in rubygems.org

Expected behavior

I'm expecting the latest source code in bigcommerce/bigcommerce-api-ruby to be what I get when I run gem install bigcommerce.

Actual behavior

While the gem is installed, its contents correspond to c2eaf31.

Steps to reproduce behavior

Run gem install bigcommerce. Open the gem and witness the contents - appears to be from several months ago.

I'm interested in implementing customer logins, so I'd love to use the latest version of the gem on a deployed environment without resorting to git

Methods don't support paging

By default the API only returns 50 results. However, the gem doesn't allow you to specify the page or the limit, so this is a problem if a store has more than 50 orders.

Questions

Hi,

I've a couple of questions:

  1. :access_token => 'ACCESS_TOKEN' . Is this client secret ? If not , how do I get this token ?
  2. I'm constantly getting a 401 unauthorized. I'm guessing bigcommerce has not yet authorized my app. Is there a way to start testing api (for example , fetch products) without waiting for the app to be authorized ?

Thanks!

V3 response

url_prefix
https://api.bigcommerce.com/stores/{store_hash}/v3

Connection
connection = Bigcommerce::Connection.build(Bigcommerce::Config.new(client_id: 'test',store_hash: 'test', access_token: 'test'))
API call
Bigcommerce::System.time(connection: connection)

Error
Bigcommerce::Forbidden: {"error":"You are authorized but your scope does not include this resource."}

Gemspec does not declare development dependencies

After disabling the gems listed in the Gemfile and installing the dependencies for this via bundle install, I've noticed that certain libraries required by this gem are not available.

e.g.

  1. $ bundle exec rake
    rake aborted!
    LoadError: cannot load such file -- rubocop/rake_task
    /Users/s/src/github.com/sgerrand/bigcommerce-api-ruby/Rakefile:10:in`require'
    /Users/s/src/github.com/sgerrand/bigcommerce-api-ruby/Rakefile:10:in `<top (required)>'
    (See full trace by running task with --trace)
    
Others apart from `RuboCop` include `Coveralls` and `RSpec`.

These gems should really be explicitly declared as development dependencies in the _gemspec_, rather than in the _Gemfile_, as they're required run rake tasks and the test suite.

Error connecting to API

I'm new to Ruby and to the BC API so there may be something obvious that I'm missing. When I'm running the following code with the proper details replaced with my store's legacy API credentials:

require 'bigcommerce'

Bigcommerce.configure do |config|
  config.auth = 'legacy'
  # You will get this url when registering for an API key
  config.url = ENV['BC_API_ENDPOINT_LEGACY']
  config.username = ENV['BC_USERNAME']
  config.api_key = ENV['BC_API_KEY']
end

puts Bigcommerce::System.time

I get the following error:

.../lib/ruby/2.3.0/net/http.rb:882:in `rescue in block in connect': Failed to open TCP connection to :80 (Connection refused - connect(2) for nil port 80) (Faraday::ConnectionFailed)

I appreciate any pointers.

Failed to parse Bigcommerce response: Connection timed out on (Forked Version)

Hi,

I have forked the original gem to add some new calls. However i am facing issue now while connecting.

Changes i have made

  1. gem 'bigcommerce', :git => 'https://github.com/ammar-ilsa/bigcommerce-api-ruby.git', ;require => 'bigcommerce' (my app Gemfile)

  2. Added a new method in api.rb of forked repo
    def get_store_data
    @connection.get '/store'
    end
    30 Method in my model
    def self.initialize_store(store_params)
    api = Bigcommerce::Api.new({
    :store_url => store_params[:api_path],
    :username => store_params[:store_user_name],
    :api_key => store_params[:api_token]
    })
    ping = api.get_store_data
    end

  3. require 'bigcommerce' in my model.

Before fork it was working fine, now it has stopped working on even 'get_time'. I am using DEMO Account at this phase.

Is the new gem thread safe?

If we are using a sidekiq with multiple threads and do

Bigcommerce.configure do |config|
  config.store_hash = ENV['BC_STORE_HASH']
  config.client_id = ENV['BC_CLIENT_ID']
  config.access_token = ENV['BC_ACCESS_TOKEN']
end

# List orders
@orders = Bigcommerce::Order.all

in each worker, and they are executing at the same time, will Bigcommerce be isolated to the correct client in each worker?

400 Bad Request "get_orders_by_date"

When I try to get all orders by date, I get an error:
..../bigcommerce-0.8.1/lib/bigcommerce/connection.rb:92:in `rescue in request': Failed to parse Bigcommerce response: 400 Bad Request (RuntimeError)

My Code:

@api = Bigcommerce::Api.new({
  store_url: @api_config['store_url'],
  username:  @api_config['username'],
  api_key:   @api_config['api_key']
})

orders = @api.get_orders_by_date('2013-03-01')

All worked fine in version 0.0.6

gem version is not updated

Hi,

The gem version is not updated when you are changing stuff, so I am not getting the last version, would appreciate if you could update it whenever you are making any changes.

Thanks

ProductReview resource needs an update

The ProductReview resource is currently written with only a GET request in mind. This resource is now fully writable on the API and needs to be updated to act like other product subresources, such as Sku.

Api#create_orders_shipments doesn't take an options argument.

The method signature for create_orders_shipments takes an order ID but not an argument for the options hash. Also, it just submits an empty hash for options.

def create_orders_shipments(id)
  @connection.post("/orders/#{id}/shipments", {})
end

Contrast that with create_optionset_option

def create_optionset_option(id, options={})
  @connection.post("/optionsets/#{id}/options", options)
end

The relevant Bigcommerce API page for creating order shipments.

Can't get any data from the api

The version from rubygems gives me this error:

{"error":"Nothing to parse. Possibly no data?"}`

But the gem from github is also not working for me:

gem 'bigcommerce', :git => "https://github.com/bigcommerce/bigcommerce-api-ruby.git"
api = Bigcommerce::Api.new({
        ...
    })

puts api.get_product(3)

.rvm/gems/ruby-1.9.3-p392/bundler/gems/bigcommerce-api-ruby-11b7895a55d5/lib/bigcommerce/connection.rb:82:in `rescue in request': Failed to parse Bigcommerce response: 404 Resource Not Found

The api key should be right, it's working fine in php.

Any idea what I'm doing wrong? ๐Ÿ

Net::HTTPBadResponse: wrong status line:

I have run the sample code:

require 'bigcommerce'

api = BigCommerce::Api.new({
    :store_url => "https://www.mybigcommercestoreurl.com",
    :username  => "admin",
    :api_key   => "myapikey"
})

which returns #<Bigcommerce...... ...>

but then this command

api.get_time

returns this:
Net::HTTPBadResponse: wrong status line: "<!DOCTYPYE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">"

Could anyone assist?

404 on get_product(id)

get_product(1) returns a 404 whereas get_product("1") returns a the wrong product

I'm expecting to get product ID number 1 when I do:
product_one = api.get_product(1)

Get all rules, skus etc for a single product does not seem to be supported

get_products_rules(options={}) returns all rules for all products. Is this intentional, as I don't see it documented in API docs?

Shouldn't there be a get_product_rules(product_id) method (and similar for sku and other product related data)

If you think those should be included I will send pull request. Please let me know.
Alex

General Guidelines for new Developers

Might I suggest a simple walk-through guiding the beginner developers. There are questions like this one http://stackoverflow.com/questions/28100315/how-to-retrieve-data-from-bigcommerce-using-rails-application where it seems help is not readily available.
A sample application that deals with one specific area of the API might be a blessing to new developers. An example in mind would be the ability to CRUD a product from a new demonstration store.
Initial setup for Private and Public Applications, etc.

get_orders_modified_since(date) returns all orders

BigCommerce::Api.new() just assigns credentials for your API.

example:

2.0.0p247 :035 > Date.today.at_beginning_of_month
 => Tue, 01 Oct 2013
2.0.0p247 :034 > BigCommerce::Api.new().connection.get_orders_modified_since(Date.today.at_beginning_of_month).map{|o| o['date_modified']}
 => ["Wed, 28 Aug 2013 16:38:13 +0000", "Thu, 22 Aug 2013 22:53:04 +0000", "Thu, 06 Jun 2013 12:37:24 +0000", "Thu, 06 Jun 2013 12:37:43 +0000", "Thu, 06 Jun 2013 12:38:00 +0000", "Thu, 06 Jun 2013 12:38:20 +0000", "Thu, 06 Jun 2013 12:38:42 +0000", "Thu, 06 Jun 2013 12:38:54 +0000", "Thu, 06 Jun 2013 12:39:10 +0000", "Thu, 06 Jun 2013 13:46:20 +0000", "Thu, 18 Apr 2013 13:21:34 +0000", "Wed, 03 Apr 2013 16:14:49 +0000", "Wed, 19 Dec 2012 19:49:15 +0000", "Wed, 19 Dec 2012 18:18:23 +0000", "Wed, 19 Dec 2012 17:17:10 +0000", "Thu, 18 Apr 2013 12:37:58 +0000", "Tue, 18 Jun 2013 21:35:32 +0000", "Wed, 19 Jun 2013 15:14:43 +0000", "Wed, 19 Jun 2013 15:22:35 +0000", "Mon, 15 Jul 2013 16:10:13 +0000", "Mon, 15 Jul 2013 16:11:01 +0000", "Mon, 15 Jul 2013 16:23:39 +0000", "Mon, 15 Jul 2013 16:25:14 +0000", "Mon, 15 Jul 2013 20:43:50 +0000", "Mon, 15 Jul 2013 20:46:29 +0000", "Mon, 15 Jul 2013 22:00:25 +0000", "Mon, 05 Aug 2013 08:34:12 +0000"]

It always returns all orders:

2.0.0p247 :038 > BigCommerce::Api.new().connection.get_orders_modified_since('2013-08-01'.to_date).size
 => 27
2.0.0p247 :039 > BigCommerce::Api.new().connection.get_orders_modified_since(Date.today.at_beginning_of_month).size
 => 27
2.0.0p247 :040 > BigCommerce::Api.new().connection.get_orders.size
 => 27

I want to get all orders modified or created since date.

Incorrect header check (Zlib::DataError)

I am getting this error attempting to use the API, I did another test locally and attempted to make the request by using Net::HTTP and turning off accept-encoding, and then I get a usefulish error back from the API:

200 HTML response with "This store is currently unavailable due to maintenance. It should be available again shortly.", I then attempted to use accept-encoding=gzip and handle the response myself but it did not appear to be a valid gzip stream.

I assume this error is because the store is under maintenance, but there seems to be an issue with the response from the API and the client unable to handle the gzipped contents or the response is invalid (and by default Ruby will pass through an accept-encoding header and handle decoding the response under the hood which explains the error).

One other interesting thing I did find was that on the "v3" version of the API I get a more useful error as JSON "You are authorized but your scope does not include this resource." but I was not even sure that v3 was an available API as all documentation appears to reference v2.

README contains incorrect example

A name error occurs when trying to connect using:

Bigcommerce::Api.new()

Whereas this works fine:

BigCommerce::Api.new()

Bigcommerce is now using a lower case 'c' so the README should remain the same and the the gem should now support calling the module with a lower case "C". The issue might also be happening because RubyGems doesn't have the latest tag of the gem.

Unable to access the connection method of Bigcommerce::Api class

Hi,

I am using the bigcommerce-api-ruby for accessing the Bigcommerce API, I am able to create bigcommerce api object also able to access the methods provided by it.
But some how I am not able to access the connection method to check whether the configurations are correct or not.
I am creating the api object using the following method

bigcommerce = BigCommerce::Api.new({ :store_url => "XXXXXXXXX", :username => "admin", :api_key => "XXXXX" })

bigcommerce.connection gives me,
NoMethodError: undefined method `connection' for #BigCommerce::Api:0xd5d04f0

Any help will be appreciated.

Methods should accept integers

An implicit casting exception is raised if you attempt to access a single resource using an integer.

get_order(100) ==> fails
get_order("100") == succeeds

A possible bug with SKU resource scopes

Hey, I am having an issue with retrieving SKU records for my testing store for a certain product using this gem.

I have a product id 121, client_id 77la31t33i3oxzwd38hk96iilrtbkvq, auth_token(access_token) hjsx0qabzg0xjp93596rnibf6hy92ki, store_hash 2lcr9f81m5. This product has options with different SKUs. I want to get a list of all SKUs for this product. App has these scopes (all maxed):

2016-07-21 13 35 58

Let's first take a look at curl:

curl --request GET https://api.bigcommerce.com/stores/2lcr9f81m5/v2/products/121/skus -H "X-Auth-Client: 77la31t33i3oxzwd38hk96iilrtbkvq" -H "X-Auth-Token: hjsx0qabzg0xjp93596rnibf6hy92ki" -H "Accept: application/json"

Result is:

[{"id":272,"product_id":121,"sku":"SKU-SIL","price":null,"adjusted_price":"22.0000","cost_price":"0.0000","upc":"","inventory_level":0,"inventory_warning_level":0,"bin_picking_number":"","weight":null,"adjusted_weight":"3.0000","is_purchasing_disabled":false,"purchasing_disabled_message":"","image_file":"","options":[{"product_option_id":126,"option_value_id":7}]},{"id":273,"product_id":121,"sku":"SKU-BLA","price":null,"adjusted_price":"22.0000","cost_price":"0.0000","upc":"","inventory_level":13,"inventory_warning_level":0,"bin_picking_number":"","weight":null,"adjusted_weight":"3.0000","is_purchasing_disabled":false,"purchasing_disabled_message":"","image_file":"","options":[{"product_option_id":126,"option_value_id":8}]},{"id":274,"product_id":121,"sku":"SKU-BLU","price":null,"adjusted_price":"22.0000","cost_price":"0.0000","upc":"","inventory_level":0,"inventory_warning_level":0,"bin_picking_number":"","weight":null,"adjusted_weight":"3.0000","is_purchasing_disabled":false,"purchasing_disabled_message":"","image_file":"","options":[{"product_option_id":126,"option_value_id":10}]},{"id":275,"product_id":121,"sku":"SKU-ORA","price":null,"adjusted_price":"22.0000","cost_price":"0.0000","upc":"","inventory_level":0,"inventory_warning_level":0,"bin_picking_number":"","weight":null,"adjusted_weight":"3.0000","is_purchasing_disabled":false,"purchasing_disabled_message":"","image_file":"","options":[{"product_option_id":126,"option_value_id":13}]}]

Perfect! Now with the gem. First, the connection:

bc_connection = Bigcommerce::Connection.build(Bigcommerce::Config.new(store_hash: "2lcr9f81m5", client_id: "77la31t33i3oxzwd38hk96iilrtbkvq", access_token: "hjsx0qabzg0xjp93596rnibf6hy92ki"))

Test it with time:

Bigcommerce::System.time(connection: bc_connection)
# {:time=>1469096822}

And now the request to get SKUs:

Bigcommerce::Sku.get('skus', product_id: 121, connection: bc_connection)

Raises this:

Bigcommerce::Forbidden: {"error":"You are authorized but your scope does not include this resource."}
from /usr/local/bundle/gems/bigcommerce-1.0.0/lib/bigcommerce/exception.rb:55:in `throw_http_exception!'

The weird thing is that calling this:

Bigcommerce::Sku.all(121, connection: bc_connection)

Returns the correct JSON.

I assume that this is a bug with SKU methods of this gem. Or is there a workaround? Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.