Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge V1 branch and fix conflicts

  • Loading branch information...
commit 5d93135346115c603dc856438990823addf37d3d 2 parents 33e4a10 + b759e0a
Mark Rickerby authored
4  .gitignore
@@ -6,3 +6,7 @@
6 6
 
7 7
 # ci_reporter
8 8
 /spec/reports
  9
+
  10
+#Ignore compiled gems
  11
+*.gem
  12
+
85  README.md
Source Rendered
@@ -6,16 +6,12 @@ Ruby apps or via the console.
6 6
 
7 7
 Note
8 8
 ----
9  
-
10  
-**The Ruby Client is still in alpha and core features of the API may be
11  
-unsupported and undocumented.**
  9
+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.
12 10
 
13 11
 Requirements
14 12
 ------------
15 13
 
16  
-- Ruby 1.8.7+
17  
-- Rubygems
18  
-- JSON
  14
+- Ruby 1.9+
19 15
 
20 16
 To connect to the API, you need the following credentials:
21 17
 
@@ -25,7 +21,7 @@ To connect to the API, you need the following credentials:
25 21
 
26 22
 A valid API key is required to authenticate requests. To grant API access for
27 23
 user, go to Control Panel > Users > Edit User and make sure that the
28  
-'Enable the XML API?' checkbox is ticked.
  24
+'Enable API access?' checkbox is ticked.
29 25
 
30 26
 Installation
31 27
 ------------
@@ -37,6 +33,13 @@ install the package directly from Rubygems:
37 33
 gem install bigcommerce
38 34
 ```
39 35
 
  36
+Note - the current gem version is 1.0. The Rubygems version might be older. 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 -
  37
+
  38
+```
  39
+gem build bigcommerce
  40
+gem install bigcommerce-1.0.gem
  41
+```
  42
+
40 43
 Configuration
41 44
 -------------
42 45
 
@@ -46,12 +49,28 @@ follows:
46 49
 ```
47 50
 require 'bigcommerce'
48 51
 
49  
-api = Bigcommerce::Api.new({
  52
+api = BigCommerce::Api.new({
  53
+	:store_url => "https://store.mybigcommerce.com",
  54
+	:username  => "admin",
  55
+	:api_key   => "d81aada4c19c34d913e18f07fd7f36ca"
  56
+})
  57
+```
  58
+
  59
+If you want to enable SSL certificates -
  60
+
  61
+```
  62
+require 'bigcommerce'
  63
+api = BigCommerce::Api.new({
50 64
 	:store_url => "https://store.mybigcommerce.com",
51 65
 	:username  => "admin",
52 66
 	:api_key   => "d81aada4c19c34d913e18f07fd7f36ca"
  67
+	:ssl_client_cert  =>  OpenSSL::X509::Certificate.new(File.read("cert.pem")),
  68
+  	:ssl_client_key   =>  OpenSSL::PKey::RSA.new(File.read("key.pem"), "passphrase, if any"),
  69
+  	:ssl_ca_file      =>  "ca_certificate.pem",
  70
+  	:verify_ssl       =>  OpenSSL::SSL::VERIFY_PEER 
53 71
 })
54 72
 ```
  73
+Remember that the fields :ssl_client_cert, :ssl_client_key, :ssl_ca_file and :verify_ssl are all requrired when enabling SSL certs.
55 74
 
56 75
 Connecting to the store
57 76
 -----------------------
@@ -68,27 +87,35 @@ Usage
68 87
 
69 88
 The API object acts as a gateway to all top level resources in the V2 API.
70 89
 
  90
+Fetch Data
71 91
 ```
72  
-$ irb
73  
->
74  
-> api = Bigcommerce::Api.new(...)
75  
->
76  
-> api.get_products.each { |product| puts product.name }
77  
->
78  
-> api.get_customers.each { |customer| puts customer.email }
79  
->
80  
-> puts api.get_orders_count
81  
->
82  
-> category = api.get_category(11)
83  
-> category.name = "Laptops"
84  
-> category.update
85  
->
86  
-> brand = Bigcommerce::Api::Brand.new
87  
-> brand.name = "Samsung"
88  
-> brand.create
89  
->
90  
-> option = api.get_option(22)
91  
-> option.delete
92  
->
  92
+orders = api.get_orders
  93
+orders = api.get_orders({:min_id=>100,:max_id=>101})
  94
+orders = api.get_orders(:is_deleted => true)
  95
+
  96
+products = api.get_products
  97
+products = api.get_products(:description=>"iphone", :condition=>"New")
  98
+
  99
+options = api.get_options
  100
+options = api.get_options(:type=>"MT")
  101
+...
  102
+
  103
+```
  104
+Create Data
  105
+```
  106
+api.create_products({:name => "Spiderman - The best return",:price => 9.99,:categories => [17],:type =>"physical",:availability => "available", :weight => 1})
  107
+
  108
+api.update_products(31,{:name => "marvel comics spiderman",:sku => "marvel-spidey-1", :inventory_tracking => "simple", :inventory_level => 500})
  109
+
  110
+api.update_orders(101,{:status_id => 12, :is_deleted => true})
  111
+
  112
+```
  113
+Update Data
  114
+
  115
+```
  116
+api.update_products(31,{:name => "marvel comics spiderman",:sku => "marvel-spidey-1", :inventory_tracking => "simple", :inventory_level => 500})
  117
+
  118
+api.update_optionsets(13,{:name => "Marvel toys"})
  119
+
93 120
 ```
94 121
 
1  bigcommerce.gemspec
@@ -4,6 +4,7 @@ require File.expand_path('../lib/bigcommerce/version', __FILE__)
4 4
 Gem::Specification.new do |s|
5 5
   s.add_dependency('activesupport')
6 6
   s.add_dependency('json')
  7
+  s.add_dependency('rest-client')
7 8
   s.add_development_dependency("ci_reporter")
8 9
   s.add_development_dependency("fakeweb")
9 10
   s.add_development_dependency("mocha")
3  lib/bigcommerce.rb
... ...
@@ -1,6 +1,7 @@
1 1
 require "cgi"
2 2
 require "json"
3  
-require "net/https"
  3
+# require "net/https"
  4
+require 'rest-client'
4 5
 require "uri"
5 6
 require 'bigcommerce/api'
6 7
 require 'bigcommerce/connection'
335  lib/bigcommerce/api.rb
@@ -22,8 +22,8 @@ def api_key=(api_key)
22 22
       @connection.api_key = api_key
23 23
     end
24 24
 
25  
-    def verify_peer=(verify)
26  
-      @connection.verify_peer = verify
  25
+    def verify_ssl=(verify)
  26
+      @connection.verify_ssl = verify
27 27
     end
28 28
 
29 29
     def ca_file=(path)
@@ -40,24 +40,28 @@ def get_time
40 40
       @connection.get '/time'
41 41
     end
42 42
 
43  
-    def get_products(params={})
44  
-      @connection.get '/products'
  43
+    #brands
  44
+
  45
+    def get_brands(options={})
  46
+      @connection.get("/brands",options)
45 47
     end
46 48
 
47  
-    def get_products_count
48  
-      @connection.get '/products/count/'
  49
+    def get_brand(id)
  50
+      @connection.get("/brands/#{id}",{})
49 51
     end
50 52
 
51  
-    def get_brands
52  
-      @connection.get '/brands'
  53
+    def create_brands(options={})
  54
+       @connection.post("/brands",options)
53 55
     end
54 56
 
55  
-    def get_product(id)
56  
-      @connection.get '/products/' + id.to_s
  57
+    def update_brand(id,options={})
  58
+       @connection.put("/brands/#{id}",options)
57 59
     end
58 60
 
59  
-    def get_categories
60  
-      @connection.get '/categories'
  61
+    #category
  62
+
  63
+    def get_categories(options={})
  64
+       @connection.get("/categories",options)
61 65
     end
62 66
 
63 67
     def get_categories_count
@@ -65,56 +69,309 @@ def get_categories_count
65 69
     end
66 70
 
67 71
     def get_category(id)
68  
-      @connection.get '/categories/' + id.to_s
  72
+      @connection.get("/categories/#{id}",{})
69 73
     end
70 74
 
71  
-    def get_orders(params={})
72  
-      @connection.get('/orders', :params => params)
  75
+    def create_categories(options={})
  76
+       @connection.post("/categories",options)
73 77
     end
74 78
 
75  
-    def get_orders_by_date(date, params={})
76  
-      if date.is_a?(String)
77  
-        date = DateTime.parse(date)
78  
-      end
79  
-      date = to_rfc2822(date)
80  
-      @connection.get('/orders', :params => params.merge!(:min_date_created => CGI::escape(date)))
  79
+    def update_category(id,options={})
  80
+       @connection.put("/categories/#{id}",options)
81 81
     end
82 82
 
83  
-    def get_orders_count
84  
-      get_count @connection.get '/orders/count'
  83
+    #country
  84
+
  85
+    def get_countries(options={})
  86
+      @connection.get("/countries",options)
85 87
     end
86 88
 
87  
-    def get_order(id)
88  
-      @connection.get '/orders/' + id.to_s
  89
+    def get_country(id)
  90
+      @connection.get("/countries/#{id}",{})
89 91
     end
90 92
 
91  
-    def get_order_products(id)
92  
-      @connection.get '/orders/' + id.to_s + '/products'
  93
+    #states
  94
+    def get_countries_states(options={})
  95
+      @connection.get("/countries/states",options)
93 96
     end
94 97
 
95  
-    def get_orders_modified_since(datetime)
96  
-      @connection.get('/orders', :headers => {'If-Modified-Since' => CGI::escape(to_rfc2822(datetime))})
  98
+    def get_countries_state(id,options={})
  99
+      @connection.get("/countries/#{id}/states",{})
97 100
     end
98 101
 
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
+     #customers
  103
+
  104
+    def get_customers(options = {})
  105
+      @connection.get("/customers",options)
102 106
     end
103 107
 
104 108
     def get_customer(id)
105  
-      @connection.get '/customers/' + id.to_s
  109
+      @connection.get('/customers/' + id.to_s,{})
  110
+    end
  111
+
  112
+     #customers/address
  113
+
  114
+    def get_customer_addresses(id,options = {})
  115
+      @connection.get("/customers/#{id}/addresses",options)
  116
+    end
  117
+
  118
+    def get_customer_address(customer_id,address_id)
  119
+      @connection.get("/customers/#{customer_id}/addresses/#{address_id}",{})
  120
+    end
  121
+
  122
+    #options
  123
+
  124
+    def get_options(options={})
  125
+       @connection.get("/options",options)
  126
+    end
  127
+
  128
+    def get_option(id)
  129
+      @connection.get("/options/#{id}",{})
  130
+    end
  131
+
  132
+    def create_options(options={})
  133
+      @connection.post("/options",options)
  134
+    end
  135
+
  136
+    def update_option(id,options={})
  137
+      @connection.put("/options/#{id}",options)
  138
+    end
  139
+
  140
+    #options/values
  141
+
  142
+    def get_options_values(options={})
  143
+       @connection.get("/options/values",options)
  144
+    end
  145
+
  146
+    def get_options_value(id)
  147
+      @connection.get("/options/#{id}/values",{})
  148
+    end
  149
+
  150
+    def create_options_values(options_id,options={})
  151
+      @connection.post("/options/#{options_id}/values",options)
  152
+    end
  153
+
  154
+    def update_options_value(options_id,values_id,options={})
  155
+      @connection.put("/options/#{options_id}/values/#{values_id}",options)
  156
+    end
  157
+
  158
+    #optionset
  159
+   
  160
+
  161
+    def get_optionsets(options={})
  162
+       @connection.get("/optionsets",options)
  163
+    end
  164
+
  165
+    def get_optionset(id)
  166
+      @connection.get("/optionsets/#{id}",{})
  167
+    end
  168
+
  169
+    def create_optionsets(options={})
  170
+      @connection.post("/optionsets",options)
  171
+    end
  172
+
  173
+    def update_optionset(id,options={})
  174
+      @connection.put("/optionsets/#{id}",options)
  175
+    end
  176
+
  177
+    #optionsets/options
  178
+
  179
+    def get_optionsets_options(options={})
  180
+       @connection.get("/optionsets/options",options)
  181
+    end
  182
+
  183
+    def get_optionsets_option(id)
  184
+      @connection.get("/optionsets/options/#{id}",{})
  185
+    end
  186
+
  187
+    def create_optionsets_options(options={})
  188
+      @connection.post("/optionsets/options",options)
  189
+    end
  190
+
  191
+    def update_optionsets_option(id,options={})
  192
+      @connection.put("/optionsets/options/#{id}",options)
  193
+    end
  194
+
  195
+    #order
  196
+
  197
+    def get_orders(options={})
  198
+      @connection.get("/orders",options)
  199
+    end
  200
+
  201
+    def get_order(id)
  202
+      @connection.get("/orders/#{id}",{})
  203
+    end
  204
+
  205
+    def update_order(id,options={})
  206
+      @connection.put("/orders/#{id}",options)
  207
+    end
  208
+
  209
+   
  210
+
  211
+    #order/coupons
  212
+    def get_orders_coupons(id)
  213
+      @connection.get("/orders/#{id}/coupons",{})
  214
+    end
  215
+
  216
+    def get_orders_product(order_id,coupon_id)
  217
+      @connection.get("/orders/#{order_id}/coupons/#{coupon_id}",{})
  218
+    end
  219
+
  220
+    #order/products
  221
+    def get_orders_products(id)
  222
+      @connection.get("/orders/#{id}/products",{})
  223
+    end
  224
+
  225
+    def get_orders_product(order_id,product_id)
  226
+      @connection.get("/orders/#{order_id}/products/#{product_id}",{})
  227
+    end
  228
+
  229
+    #order/shipments
  230
+    def get_orders_shipments(id)
  231
+      @connection.get("/orders/#{id}/shipments",{})
  232
+    end
  233
+
  234
+    def create_orders_shipments(id)
  235
+      @connection.post("/orders/#{id}/shipments",{})
  236
+    end
  237
+
  238
+    def get_orders_shipment(order_id,shipment_id)
  239
+      @connection.get("/orders/#{order_id}/shipments/#{shipment_id}",{})
  240
+    end
  241
+
  242
+    def update_orders_shipment(order_id,shipment_id,options={})
  243
+      @connection.put("/orders/#{order_id}/shipments/#{shipment_id}",options)
  244
+    end
  245
+
  246
+    #orders/shippingaddresses
  247
+    def get_orders_shippingaddresses(id)
  248
+      @connection.get("/orders/#{id}/shippingaddresses",{})
  249
+    end
  250
+
  251
+    def get_orders_shippingaddress(order_id,shippingaddress_id)
  252
+      @connection.get("/orders/#{order_id}/shippingaddresses/#{shippingaddress_id}",{})
  253
+    end
  254
+
  255
+    #orderstatuses
  256
+    def get_orderstatuses(options={})
  257
+      @connection.get("/orderstatuses",options)
  258
+    end
  259
+
  260
+    def get_orderstatuses(id)
  261
+      @connection.get("/orderstatuses/#{id}",{})
  262
+    end
  263
+
  264
+    #products
  265
+    def get_products(options={})
  266
+      @connection.get("/products",options)
  267
+    end
  268
+
  269
+    def get_product(id)
  270
+      @connection.get("/products/#{id}",{})
  271
+    end
  272
+
  273
+     def create_products(options={})
  274
+      @connection.post('/products', options)
  275
+    end
  276
+
  277
+    def update_products(id, options={})
  278
+      @connection.put("/products/#{id}", options)
  279
+    end
  280
+    
  281
+    #products/bulkdiscount
  282
+    def get_products_discountrules(options={})
  283
+      @connection.get("/products/discountrules",options)
  284
+    end
  285
+
  286
+    def get_products_discountrule(product_id,discountrule_id)
  287
+      @connection.get("/products/#{product_id}/discountrules/#{discountrule_id}",{})
  288
+    end
  289
+
  290
+    #products/configurablefields
  291
+    def get_products_configurablefields(options={})
  292
+      @connection.get("/products/configurablefields",options)
  293
+    end
  294
+
  295
+    def get_products_configurablefield(product_id,configurable_field_id)
  296
+      @connection.get("/products/#{product_id}/configurablefields/#{configurable_field_id}",{})
  297
+    end
  298
+
  299
+    #products/customfields
  300
+    def get_products_customfields(options={})
  301
+      @connection.get("/products/customfields",options)
  302
+    end
  303
+
  304
+    def get_products_customfield(product_id,custom_field_id)
  305
+      @connection.get("/products/#{product_id}/customfields/#{custom_field_id}",{})
  306
+    end
  307
+
  308
+    #products/images
  309
+    def get_products_images(options={})
  310
+      @connection.get("/products/images",options)
  311
+    end
  312
+
  313
+    def create_products_images(options={})
  314
+      @connection.post("/products/images",options)
  315
+    end
  316
+
  317
+    def get_products_image(product_id,image_id)
  318
+      @connection.get("/products/#{product_id}/images/#{image_id}",{})
  319
+    end
  320
+
  321
+    def update_products_image(product_id,image_id,options={})
  322
+      @connection.put("/products/#{product_id}/images/#{image_id}",options)
  323
+    end
  324
+
  325
+    #products/options
  326
+    def get_products_customfields(options={})
  327
+      @connection.get("/products/options",options)
  328
+    end
  329
+
  330
+    def get_products_option(product_id,option_id)
  331
+      @connection.get("/products/#{product_id}/options/#{option_id}",{})
  332
+    end
  333
+
  334
+    #products/rules
  335
+    def get_products_rules(options={})
  336
+      @connection.get("/products/rules",options)
  337
+    end
  338
+
  339
+    def create_products_rules(options={})
  340
+      @connection.post("/products/rules",options)
  341
+    end
  342
+
  343
+    def get_products_rule(product_id,rule_id)
  344
+      @connection.get("/products/#{product_id}/rules/#{rule_id}",{})
  345
+    end
  346
+
  347
+    def update_products_rule(product_id,rule_id,options={})
  348
+      @connection.put("/products/#{product_id}/rules/#{rule_id}",options)
  349
+    end
  350
+
  351
+    #products/skus
  352
+    def get_products_skus(options={})
  353
+      @connection.get("/products/skus",options)
  354
+    end
  355
+
  356
+    def create_products_skus(options={})
  357
+      @connection.post("/products/skus",options)
  358
+    end
  359
+
  360
+    def get_products_sku(product_id,sku_id)
  361
+      @connection.get("/products/#{product_id}/skus/#{sku_id}",{})
106 362
     end
107 363
 
108  
-    def get_customer_count
109  
-      @connection.get '/customers/count'
  364
+    def update_products_sku(product_id,sku_id,options={})
  365
+      @connection.put("/products/#{product_id}/skus/#{sku_id}",options)
110 366
     end
111 367
 
112  
-    def create_product(attributes)
113  
-      @connection.post('/products', :body => attributes.to_xml(:root => 'product'))
  368
+    #products/videos
  369
+    def get_products_videos(options={})
  370
+      @connection.get("/products/videos",options)
114 371
     end
115 372
 
116  
-    def update_product(id, attributes)
117  
-      @connection.put("/products/#{id}", :body => attributes.to_xml(:root => 'product'))
  373
+    def get_products_video(product_id,video_id)
  374
+      @connection.get("/products/#{product_id}/videos/#{video_id}",{})
118 375
     end
119 376
 
120 377
     private
176  lib/bigcommerce/connection.rb
@@ -18,90 +18,142 @@ def api_key=(api_key)
18 18
     end
19 19
 
20 20
     def verify_peer=(verify)
21  
-      @configuration[:verify_peer] = verify
  21
+      @configuration[:verify_ssl] = verify
22 22
     end
23 23
 
24  
-    def ca_file=(path)
25  
-      @configuration.ca_file = path
  24
+    def ssl_ca_file=(path)
  25
+      @configuration.ssl_ca_file = path
26 26
     end
27 27
 
28  
-    def get(path, options = {})
29  
-      request(:get, path, options)
  28
+    def ssl_client_key=(path,passphrase=nil)
  29
+      if passphrase.nil?
  30
+        @configuration.ssl_client_key = OpenSSL::PKey::RSA.new(File.read(path))
  31
+      else
  32
+        @configuration.ssl_client_key = OpenSSL::PKey::RSA.new(File.read(path), passphrase)
  33
+      end
30 34
     end
31 35
 
32  
-    def post(path, options = {})
33  
-      request(:post, path, options)
  36
+    def ssl_client_cert=(path)
  37
+      @configuration.client_cert = OpenSSL::X509::Certificate.new(File.read(path))
34 38
     end
35 39
 
36  
-    def put(path, options = {})
37  
-      request(:put, path, options)
  40
+    def get(path, options = {}, headers = {})
  41
+      request(:get, path, options, headers)
38 42
     end
39 43
 
40  
-    def delete(path, options = {})
41  
-      request(:delete, path, options)
  44
+    def post(path, options = {}, headers = {})
  45
+      request(:post, path, options, headers)
42 46
     end
43 47
 
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?
  48
+    def put(path, options = {}, headers = {})
  49
+      request(:put, path, options, headers)
  50
+    end
49 51
 
50  
-      unless (param_string.nil? || param_string.empty?)
51  
-        uri = URI.parse("#{url}?#{param_string}")
52  
-      else
53  
-        uri = URI.parse(url)
  52
+    def delete(path, options = {}, headers = {})
  53
+      request(:delete, path, options, headers)
  54
+    end
  55
+
  56
+    def request(method, path, options,headers={})
  57
+      restclient = RestClient::Resource.new "#{@configuration[:store_url]}/api/v2#{path}.json", @configuration[:username], @configuration[:api_key]
  58
+      if @configuration[:ssl_client_key] && @configuration[:ssl_client_cert] && @configuration[:ssl_ca_file]
  59
+        restclient = RestClient::Resource.new(
  60
+          "#{@configuration[:store_url]}/api/v2#{path}.json",
  61
+          :username => @configuration[:username], 
  62
+          :password => @configuration[:api_key],
  63
+          :ssl_client_cert  =>  @configuration[:ssl_client_cert],
  64
+          :ssl_client_key   =>  @configuration[:ssl_client_key],
  65
+          :ssl_ca_file      =>  @configuration[:ssl_ca_file],
  66
+          :verify_ssl       =>  @configuration[:verify_ssl]
  67
+        )
  68
+      end
  69
+      begin
  70
+        response = case method
  71
+                    when :get then
  72
+                      restclient.get :params => options, :accept => :json, :content_type => :json
  73
+                    when :post then
  74
+                      restclient.post(options.to_json, :content_type => :json, :accept => :json)
  75
+                    when :put then
  76
+                      restclient.put(options.to_json, :content_type => :json, :accept => :json)
  77
+                    when :delete then
  78
+                      restclient.delete
  79
+                  
  80
+                    end
  81
+        JSON.parse response
  82
+      rescue => e
  83
+         {"error"=>"Nothing to parse. Possibly no data?"}.to_json
54 84
       end
  85
+      
  86
+    end
55 87
 
56  
-      http = Net::HTTP.new(uri.host, uri.port)
57  
-      http.use_ssl = true
  88
+  #   def request(method, path, options = {})
  89
+  #     #body, params = options.values_at(:body, :params)
  90
+  #     #headers = options[:headers] || {}
58 91
 
59  
-      if @configuration.has_key?(:verify_peer) && @configuration[:verify_peer]
60  
-        http.verify_mode = OpenSSL::SSL::VERIFY_PEER
61  
-      else
62  
-        http.verify_mode = OpenSSL::SSL::VERIFY_NONE
63  
-      end
  92
+  #     headers = {}
  93
+  #     uri = URI.parse(@configuration[:store_url] + '/api/v2' + path)
  94
+  #     #param_string = hash_to_params(params) unless params.nil? || params.empty?
64 95
 
65  
-      http.ca_file = @configuration[:ca_path] if @configuration.has_key?(:ca_path)
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
  96
+  #     # unless (param_string.nil? || param_string.empty?)
  97
+  #     #   uri = URI.parse("#{url}?#{param_string}")
  98
+  #     # else
  99
+  #     #   uri = URI.parse(url)
  100
+  #     # end
92 101
 
93  
-    def hash_to_params(hash)
94  
-      return nil if hash.nil? || hash.empty?
  102
+  #     http = Net::HTTP.new(uri.host, uri.port)
  103
+  #     http.use_ssl = true
95 104
 
96  
-      # convert the hash to URL params
97  
-      return hash.map {|pair| pair.join("=")}.join("&")
  105
+  #     if @configuration.has_key?(:verify_peer) && @configuration[:verify_peer]
  106
+  #       http.verify_mode = OpenSSL::SSL::VERIFY_PEER
  107
+  #     else
  108
+  #       http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  109
+  #     end
98 110
 
  111
+  #     http.ca_file = @configuration[:ca_path] if @configuration.has_key?(:ca_path)
99 112
 
100  
-    end
101  
-  end
  113
+  #     request = case method
  114
+  #                 when :get then
  115
+  #                   Net::HTTP::Get.new(uri.request_uri)
  116
+  #                 when :post then
  117
+  #                   Net::HTTP::Post.new(uri.request_uri)
  118
+  #                 when :put then
  119
+  #                   Net::HTTP::Put.new(uri.request_uri)
  120
+  #                 when :delete then
  121
+  #                   Net::HTTP::Delete.new(uri.request_uri)
  122
+  #               end
  123
+
  124
+  #     request.basic_auth(@configuration[:username], @configuration[:api_key])
  125
+  #     request.add_field 'Accept', 'application/json'
  126
+  #     request.add_field 'Content-Type', 'application/json'
  127
+  #     headers.each { |k,v| request.add_field(k, v) }
  128
+
  129
+  #     #add request body
  130
+  #     case method
  131
+  #     when :post then
  132
+  #       request.set_form_data(options)
  133
+  #     end
  134
+
  135
+  #     response = http.request(request)
  136
+
  137
+  #     return case response
  138
+  #              when Net::HTTPSuccess, Net::HTTPRedirection
  139
+  #                JSON.parse(response.body || "{}")
  140
+  #              else
  141
+  #                false
  142
+  #            end
  143
+  #   end
  144
+
  145
+  #   def hash_to_params(hash)
  146
+  #     return nil if hash.nil? || hash.empty?
  147
+
  148
+  #     # convert the hash to URL params
  149
+  #     return hash.map {|pair| pair.join("=")}.join("&")
  150
+
  151
+
  152
+  #   end
  153
+   end
102 154
 
103 155
 
104  
-  class HttpError < Exception
  156
+  # class HttpError < Exception
105 157
 
106  
-  end
  158
+  # end
107 159
 end
4  lib/bigcommerce/version.rb
... ...
@@ -1,6 +1,6 @@
1 1
 module Bigcommerce
2  
-  major = 0
  2
+  major = 1
3 3
   minor = 0
4  
-  patch = 6
  4
+  patch = 0
5 5
   VERSION = [major, minor, patch].join('.') unless defined? Bigcommerce::VERSION
6 6
 end
9  spec/fixtures/brands.json
... ...
@@ -0,0 +1,9 @@
  1
+[{
  2
+  "id": 10,
  3
+  "name": "Xmen",
  4
+  "page_title": "X men brand",
  5
+  "meta_keywords": null,
  6
+  "meta_description": null,
  7
+  "image_file": "t/apirmzk0a__43675.jpg",
  8
+  "search_keywords": "xmen, awesomeness"
  9
+}]
20  spec/fixtures/categories.json
... ...
@@ -0,0 +1,20 @@
  1
+[
  2
+    {
  3
+        "id": 1,
  4
+        "parent_id": 0,
  5
+        "name": "Shop Mac",
  6
+        "description": "",
  7
+        "sort_order": 0,
  8
+        "page_title": "",
  9
+        "meta_keywords": "",
  10
+        "meta_description": "",
  11
+        "layout_file": "category.html",
  12
+        "parent_category_list": [
  13
+            1
  14
+        ],
  15
+        "image_file": "",
  16
+        "is_visible": true,
  17
+        "search_keywords": "",
  18
+        "url": "/shop-mac/"
  19
+    }
  20
+]
10  spec/fixtures/countries.json
... ...
@@ -0,0 +1,10 @@
  1
+[{
  2
+              "id": 226,
  3
+              "country": "United States",
  4
+              "country_iso2": "US",
  5
+              "country_iso3": "USA",
  6
+              "states": {
  7
+                  "url": "https://store-bwvr466.mybigcommerce.com/api/v2/countries/226/states.json",
  8
+                  "resource": "/countries/226/states"
  9
+              }
  10
+          }]

0 notes on commit 5d93135

Please sign in to comment.
Something went wrong with that request. Please try again.