b2w 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cb2500073ac4f7430bf265e976e88bb866ff5abf
4
+ data.tar.gz: 2d59b591cdc5e080d5164dd06c056d7903b79b1d
5
+ SHA512:
6
+ metadata.gz: 30e54bd3bd1e7f9db4d954ae01e0490a873e59305f4152da36549971da47bab640a92172bc3ee47fb96bbc2d4c39efe1bb9031e1321ed59a85b09027d398be67
7
+ data.tar.gz: ccfb773f377db2bf22ac16dadf7be45dc3a6604e823853f91e32e03ad3edde65b0283b52f31d12d873df4cb1c905ad3cf97b0aeb32c67fa3853ad0314581d549
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in b2w.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Diego Carrion
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # B2w
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'b2w'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install b2w
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/b2w/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new('spec')
data/b2w.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'b2w/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "b2w"
8
+ spec.version = B2W::VERSION
9
+ spec.authors = ["Diego Carrion", "Wesley Conde"]
10
+ spec.email = ["dc.rec1@gmail.com", "kerponeis@gmail.com"]
11
+ spec.summary = "Ruby interface to B2W"
12
+ spec.description = "B2W Digital API"
13
+ spec.homepage = "https://www.github.com/wesleyskap/b2w-ruby"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "rest-client", '~> 1.7', '>= 1.7.2'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake", '~> 10.4', '>= 10.4.2'
25
+ spec.add_development_dependency "rspec", '~> 3.1', '>= 3.1.0'
26
+ spec.add_development_dependency "webmock", '~> 1.20', '>= 1.20.4'
27
+ spec.add_development_dependency "vcr", '~> 2.9', '>= 2.9.3'
28
+ spec.add_dependency "pry", "~> 0.10.1"
29
+ end
data/lib/b2w/base.rb ADDED
@@ -0,0 +1,55 @@
1
+ module B2W
2
+ class Base
3
+ def [](key)
4
+ @data[key]
5
+ end
6
+
7
+ def initialize(data)
8
+ @data = data
9
+ end
10
+
11
+ def persisted?
12
+ self[:persisted]
13
+ end
14
+
15
+ def self.get(resource, params = {})
16
+ JSON.parse(execute(:get, "#{endpoint}/#{resource}?#{to_params(params)}"))
17
+ end
18
+
19
+ def self.post(resource, payload, &block)
20
+ execute(:post, "#{endpoint}/#{resource}", body: payload, &block)
21
+ end
22
+
23
+ def put(resource, path, payload)
24
+ self.class.execute(:put, "#{self.class.endpoint}/#{resource}/#{path}", body: payload)
25
+ end
26
+
27
+ def self.execute(method, url, params = {}, &block)
28
+ if params[:body]
29
+ params[:headers] = { content_type: 'application/json;charset=UTF-8' }
30
+ params[:payload] = JSON.generate params[:body]
31
+ end
32
+ RestClient::Request.execute({ method: method, url: url, user: token }.merge(params), &block)
33
+ end
34
+
35
+ def self.endpoint
36
+ "https://#{version}.bonmarketplace.com.br"
37
+ end
38
+
39
+ def self.token
40
+ B2W.config[:token]
41
+ end
42
+
43
+ def self.version
44
+ B2W.config[:sandbox] ? "api-sandbox" : "api-marketplace"
45
+ end
46
+
47
+ def self.to_params(params)
48
+ params.map { |key, value| "#{camel_case(key)}=#{value}" }.join "&"
49
+ end
50
+
51
+ def self.camel_case(key)
52
+ key.to_s.gsub(/_\w/) { $&.upcase }.gsub(/_/, '')
53
+ end
54
+ end
55
+ end
data/lib/b2w/order.rb ADDED
@@ -0,0 +1,25 @@
1
+ module B2W
2
+ class Order < Base
3
+ def self.all(params = {})
4
+ get(:order, params)["orders"].map { |params| new params }
5
+ end
6
+
7
+ def self.find(id)
8
+ get("order/#{id}")
9
+ end
10
+
11
+ def self.approved(params = {})
12
+ all({ status: 'APPROVED' }.merge(params))
13
+ end
14
+
15
+ def processing!
16
+ put(:order, "#{self['id']}/status", status: 'PROCESSING')
17
+ end
18
+
19
+ %w(invoiced shipped delivered).each do |status|
20
+ define_method "#{status}!" do |body|
21
+ put(:order, "#{self['id']}/status", status: status.upcase, status => body)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,45 @@
1
+ module B2W
2
+ class Product < Base
3
+ def self.create!(params)
4
+ post(:product, params) do |body, request, result|
5
+ log "request: #{request.to_s}"
6
+ log "body: #{body}"
7
+ log "result: #{result.to_s}"
8
+ new persisted: result.is_a?(Net::HTTPCreated)
9
+ end
10
+ end
11
+
12
+ def update!(params)
13
+ bool_operation { self.class.post "product/#{sku}/sku", params }
14
+ end
15
+
16
+ def update_price!
17
+ put(:sku, "#{sku}/price", sellPrice: self['sell_price'], listPrice: self['list_price'])
18
+ end
19
+
20
+ def update_stock!
21
+ put(:sku, "#{sku}/stock", quantity: self['quantity'])
22
+ end
23
+
24
+ def exists?
25
+ bool_operation { self.class.get "sku/#{sku}" }
26
+ end
27
+
28
+ private
29
+
30
+ def bool_operation
31
+ begin
32
+ yield
33
+ true
34
+ rescue RestClient::ResourceNotFound
35
+ false
36
+ rescue RestClient::UnprocessableEntity
37
+ false
38
+ end
39
+ end
40
+
41
+ def sku
42
+ self['sku']
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ module B2W
2
+ VERSION = "0.1.2"
3
+ end
data/lib/b2w.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'rest-client'
2
+ require "b2w/base"
3
+ require "b2w/order"
4
+ require "b2w/product"
5
+ require "b2w/version"
6
+ require "json"
7
+
8
+ module B2W
9
+ def self.config!(config)
10
+ @config = config
11
+ end
12
+
13
+ def self.config
14
+ @config
15
+ end
16
+ end
@@ -0,0 +1,41 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://A01D5EA1EE4A33E02C02939F4B0E15D3:@api-sandbox.bonmarketplace.com.br/order/67
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - "*/*; q=0.5, application/xml"
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - nginx/1.7.5
23
+ Date:
24
+ - Mon, 27 Apr 2015 13:43:47 GMT
25
+ Content-Type:
26
+ - application/json;charset=utf-8
27
+ Transfer-Encoding:
28
+ - chunked
29
+ Connection:
30
+ - keep-alive
31
+ X-Access-Control-Realm:
32
+ - external
33
+ body:
34
+ encoding: UTF-8
35
+ string: '{"id":"67","siteId":"03-67-01","store":"SUBMARINO","purchaseDate":"2014-03-11","lastUpdate":"2014-04-28","status":"PROCESSING","invoiced":{"issueDate":"2014-04-28"},"estimatedDeliveryDate":"2014-03-25","customer":{"pf":{"cpf":"11111111111","name":"Cliente
36
+ de Teste SandBox11111111111"},"deliveryAddress":{"street":"Rua de teste sandbox","number":"123","additionalInfo":"Complemento
37
+ de teste sandbox","reference":"Referencia de teste sandbox","neighborhood":"Bairro
38
+ de Teste sandbox","city":"RIO DE JANEIRO","state":"RJ","zipcode":"20081902"},"telephones":{"main":{"ddd":"21","number":"23456789"},"secondary":{"ddd":"21","number":"23456788"},"business":{"ddd":"21","number":"23456787"}}},"totalAmount":24.66,"totalFreight":24.0,"totalDiscount":0.0,"products":[{"link":{"id":"ITEM213","rel":"sku","href":"https://api-sandbox.bonmarketplace.com.br/sku/ITEM213"},"quantity":1,"price":0.33,"freight":12.0,"discount":0.0},{"link":{"id":"ITEM214","rel":"sku","href":"https://api-sandbox.bonmarketplace.com.br/sku/ITEM214"},"quantity":1,"price":0.33,"freight":12.0,"discount":0.0}]}'
39
+ http_version:
40
+ recorded_at: Mon, 27 Apr 2015 13:45:33 GMT
41
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,44 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://A01D5EA1EE4A33E02C02939F4B0E15D3:@api-sandbox.bonmarketplace.com.br/order
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - "*/*; q=0.5, application/xml"
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - nginx/1.7.5
23
+ Date:
24
+ - Mon, 27 Apr 2015 13:43:47 GMT
25
+ Content-Type:
26
+ - application/json;charset=utf-8
27
+ Transfer-Encoding:
28
+ - chunked
29
+ Connection:
30
+ - keep-alive
31
+ X-Access-Control-Realm:
32
+ - external
33
+ body:
34
+ encoding: UTF-8
35
+ string: '{"orders":[{"id":"67","siteId":"03-67-01","store":"SUBMARINO","purchaseDate":"2014-03-11","lastUpdate":"2014-04-28","status":"PROCESSING","invoiced":{"issueDate":"2014-04-28"},"estimatedDeliveryDate":"2014-03-25","customer":{"pf":{"cpf":"11111111111","name":"Cliente
36
+ de Teste SandBox11111111111"},"deliveryAddress":{"street":"Rua de teste sandbox","number":"123","additionalInfo":"Complemento
37
+ de teste sandbox","reference":"Referencia de teste sandbox","neighborhood":"Bairro
38
+ de Teste sandbox","city":"RIO DE JANEIRO","state":"RJ","zipcode":"20081902"},"telephones":{"main":{"ddd":"21","number":"23456789"},"secondary":{"ddd":"21","number":"23456788"},"business":{"ddd":"21","number":"23456787"}}},"totalAmount":24.66,"totalFreight":24.0,"totalDiscount":0.0,"products":[{"link":{"id":"ITEM213","rel":"sku","href":"https://api-sandbox.bonmarketplace.com.br/sku/ITEM213"},"quantity":1,"price":0.33,"freight":12.0,"discount":0.0},{"link":{"id":"ITEM214","rel":"sku","href":"https://api-sandbox.bonmarketplace.com.br/sku/ITEM214"},"quantity":1,"price":0.33,"freight":12.0,"discount":0.0}]},{"id":"68","siteId":"03-68-01","store":"SUBMARINO","purchaseDate":"2014-03-11","lastUpdate":"2014-04-28","status":"PROCESSING","invoiced":{"issueDate":"2014-04-28"},"estimatedDeliveryDate":"2014-03-25","customer":{"pf":{"cpf":"11111111111","name":"Cliente
39
+ de Teste SandBox11111111111"},"deliveryAddress":{"street":"Rua de teste sandbox","number":"123","additionalInfo":"Complemento
40
+ de teste sandbox","reference":"Referencia de teste sandbox","neighborhood":"Bairro
41
+ de Teste sandbox","city":"RIO DE JANEIRO","state":"RJ","zipcode":"20081902"},"telephones":{"main":{"ddd":"21","number":"23456789"},"secondary":{"ddd":"21","number":"23456788"},"business":{"ddd":"21","number":"23456787"}}},"totalAmount":24.66,"totalFreight":24.0,"totalDiscount":0.0,"products":[{"link":{"id":"ITEM213","rel":"sku","href":"https://api-sandbox.bonmarketplace.com.br/sku/ITEM213"},"quantity":1,"price":0.33,"freight":12.0,"discount":0.0},{"link":{"id":"ITEM214","rel":"sku","href":"https://api-sandbox.bonmarketplace.com.br/sku/ITEM214"},"quantity":1,"price":0.33,"freight":12.0,"discount":0.0}]}],"total":2}'
42
+ http_version:
43
+ recorded_at: Mon, 27 Apr 2015 13:45:34 GMT
44
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,38 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://A01D5EA1EE4A33E02C02939F4B0E15D3:@api-sandbox.bonmarketplace.com.br/sku/0123
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - "*/*; q=0.5, application/xml"
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 404
19
+ message: Not Found
20
+ headers:
21
+ Server:
22
+ - nginx/1.7.5
23
+ Date:
24
+ - Mon, 27 Apr 2015 13:43:48 GMT
25
+ Content-Type:
26
+ - application/json;charset=utf-8
27
+ Content-Length:
28
+ - '57'
29
+ Connection:
30
+ - keep-alive
31
+ X-Access-Control-Realm:
32
+ - external
33
+ body:
34
+ encoding: UTF-8
35
+ string: '{"httpStatusCode":404,"message":"SkuId:[0123] not found"}'
36
+ http_version:
37
+ recorded_at: Mon, 27 Apr 2015 13:45:35 GMT
38
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,38 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://A01D5EA1EE4A33E02C02939F4B0E15D3:@api-sandbox.bonmarketplace.com.br/sku/b2w-ruby-1
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - "*/*; q=0.5, application/xml"
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - nginx/1.7.5
23
+ Date:
24
+ - Mon, 27 Apr 2015 13:43:48 GMT
25
+ Content-Type:
26
+ - application/json;charset=utf-8
27
+ Transfer-Encoding:
28
+ - chunked
29
+ Connection:
30
+ - keep-alive
31
+ X-Access-Control-Realm:
32
+ - external
33
+ body:
34
+ encoding: UTF-8
35
+ string: '{"id":"b2w-ruby-1","name":"B2W Ruby","ean":["1234567890128"],"height":1.0,"width":0.003333,"length":1.0,"weight":1.0,"stockQuantity":3,"enable":true,"price":{"listPrice":10.0,"sellPrice":10.0},"marketStructure":{"categoryId":9999,"subCategoryId":9999,"familyId":9999,"subFamilyId":9999},"crossDocking":0,"link":{"id":"b2w-ruby-1","rel":"product","href":"https://api-sandbox.bonmarketplace.com.br/product/b2w-ruby-1"}}'
36
+ http_version:
37
+ recorded_at: Mon, 27 Apr 2015 13:45:35 GMT
38
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,46 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://A01D5EA1EE4A33E02C02939F4B0E15D3:@api-sandbox.bonmarketplace.com.br/product
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"id":"b2w-ruby-2","name":"B2W Ruby","sku":[{"id":"b2w-ruby-2","name":"B2W
9
+ Ruby","ean":["invalid"],"weight":1,"stockQuantity":3,"enable":true,"price":{"sellPrice":10,"listPrice":10}}],"manufacturer":{"name":"Digital
10
+ Pages","model":"b2w-ruby","warrantyTime":1},"deliveryType":"SHIPMENT","nbm":{"number":"49019900","origin":"1"}}'
11
+ headers:
12
+ Accept:
13
+ - "*/*; q=0.5, application/xml"
14
+ Accept-Encoding:
15
+ - gzip, deflate
16
+ Content-Type:
17
+ - application/json;charset=UTF-8
18
+ Content-Length:
19
+ - '327'
20
+ User-Agent:
21
+ - Ruby
22
+ response:
23
+ status:
24
+ code: 422
25
+ message: Unprocessable Entity
26
+ headers:
27
+ Server:
28
+ - nginx/1.7.5
29
+ Date:
30
+ - Mon, 27 Apr 2015 13:43:47 GMT
31
+ Content-Type:
32
+ - application/json;charset=utf-8
33
+ Content-Length:
34
+ - '224'
35
+ Connection:
36
+ - keep-alive
37
+ X-Access-Control-Realm:
38
+ - external
39
+ body:
40
+ encoding: UTF-8
41
+ string: '{"httpStatusCode":422,"message":"Nao foi possivel processar as instrucoes
42
+ contidas na requisicao","validationErrors":[{"fieldName":"sku[0].ean","restrictionType":"INVALID","message":"field
43
+ should be a number. Ean:invalid"}]}'
44
+ http_version:
45
+ recorded_at: Mon, 27 Apr 2015 13:45:34 GMT
46
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,46 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://A01D5EA1EE4A33E02C02939F4B0E15D3:@api-sandbox.bonmarketplace.com.br/product
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"id":"b2w-ruby-1","name":"B2W Ruby","sku":[{"id":"b2w-ruby-1","name":"B2W
9
+ Ruby","ean":["9789896370107"],"urlImage":["http://imagens.isupply.com.br/436/web/9788539903436.jpg"],"weight":1,"stockQuantity":3,"enable":true,"price":{"sellPrice":10,"listPrice":10}}],"manufacturer":{"name":"Digital
10
+ Pages","model":"b2w-ruby","warrantyTime":1},"deliveryType":"SHIPMENT","nbm":{"number":"49019900","origin":"1"}}'
11
+ headers:
12
+ Accept:
13
+ - "*/*; q=0.5, application/xml"
14
+ Accept-Encoding:
15
+ - gzip, deflate
16
+ Content-Type:
17
+ - application/json;charset=UTF-8
18
+ Content-Length:
19
+ - '404'
20
+ User-Agent:
21
+ - Ruby
22
+ response:
23
+ status:
24
+ code: 201
25
+ message: Created
26
+ headers:
27
+ Server:
28
+ - nginx/1.7.5
29
+ Date:
30
+ - Mon, 27 Apr 2015 13:43:47 GMT
31
+ Content-Type:
32
+ - application/json;charset=utf-8
33
+ Content-Length:
34
+ - '0'
35
+ Connection:
36
+ - keep-alive
37
+ X-Access-Control-Realm:
38
+ - external
39
+ Location:
40
+ - https://api-sandbox.bonmarketplace.com.br/product/b2w-ruby-1
41
+ body:
42
+ encoding: UTF-8
43
+ string: ''
44
+ http_version:
45
+ recorded_at: Mon, 27 Apr 2015 13:45:34 GMT
46
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,42 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://A01D5EA1EE4A33E02C02939F4B0E15D3:@api-sandbox.bonmarketplace.com.br/product/invalid/sku
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"id":"b2w-ruby-1","name":"B2W Ruby","ean":["9789896370107"],"weight":1,"stockQuantity":3,"enable":true,"price":{"sellPrice":10,"listPrice":10}}'
9
+ headers:
10
+ Accept:
11
+ - "*/*; q=0.5, application/xml"
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ Content-Type:
15
+ - application/json;charset=UTF-8
16
+ Content-Length:
17
+ - '144'
18
+ User-Agent:
19
+ - Ruby
20
+ response:
21
+ status:
22
+ code: 422
23
+ message: Unprocessable Entity
24
+ headers:
25
+ Server:
26
+ - nginx/1.7.5
27
+ Date:
28
+ - Mon, 27 Apr 2015 13:43:48 GMT
29
+ Content-Type:
30
+ - application/json;charset=utf-8
31
+ Content-Length:
32
+ - '86'
33
+ Connection:
34
+ - keep-alive
35
+ X-Access-Control-Realm:
36
+ - external
37
+ body:
38
+ encoding: UTF-8
39
+ string: '{"httpStatusCode":422,"message":"ProductId:[invalid] not found","validationErrors":[]}'
40
+ http_version:
41
+ recorded_at: Mon, 27 Apr 2015 13:45:35 GMT
42
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,44 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://A01D5EA1EE4A33E02C02939F4B0E15D3:@api-sandbox.bonmarketplace.com.br/product/b2w-ruby-1/sku
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"id":"b2w-ruby-1","name":"B2W Ruby","ean":["9789896370107"],"urlImage":["http://imagens.isupply.com.br/436/web/9788539903436.jpg"],"weight":1,"stockQuantity":3,"enable":true,"price":{"sellPrice":10,"listPrice":10}}'
9
+ headers:
10
+ Accept:
11
+ - "*/*; q=0.5, application/xml"
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ Content-Type:
15
+ - application/json;charset=UTF-8
16
+ Content-Length:
17
+ - '215'
18
+ User-Agent:
19
+ - Ruby
20
+ response:
21
+ status:
22
+ code: 201
23
+ message: Created
24
+ headers:
25
+ Server:
26
+ - nginx/1.7.5
27
+ Date:
28
+ - Mon, 27 Apr 2015 13:43:48 GMT
29
+ Content-Type:
30
+ - application/json;charset=utf-8
31
+ Content-Length:
32
+ - '0'
33
+ Connection:
34
+ - keep-alive
35
+ X-Access-Control-Realm:
36
+ - external
37
+ Location:
38
+ - https://api-sandbox.bonmarketplace.com.br/product/b2w-ruby-1/sku/b2w-ruby-1
39
+ body:
40
+ encoding: UTF-8
41
+ string: ''
42
+ http_version:
43
+ recorded_at: Mon, 27 Apr 2015 13:45:35 GMT
44
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,107 @@
1
+ require 'spec_helper'
2
+
3
+ describe B2W::Order do
4
+
5
+ before { @sandbox_endpoint = 'https://api-sandbox.bonmarketplace.com.br' }
6
+
7
+ describe ".find" do
8
+ it 'returns the order details' do
9
+ VCR.use_cassette('order') do
10
+ expect(B2W::Order.find(67)["status"]).to eql "PROCESSING"
11
+ end
12
+ end
13
+ end
14
+
15
+ describe ".all" do
16
+ it "returns the orders details" do
17
+ VCR.use_cassette('orders') do
18
+ expect(B2W::Order.all.first["customer"]['pf']['cpf']).to eql "11111111111"
19
+ end
20
+ end
21
+ end
22
+
23
+ describe ".approved" do
24
+ it "returns the approved orders details" do
25
+ expect(RestClient::Request).to receive(:execute) do |params|
26
+ expect(params[:url]).to include("status=APPROVED")
27
+ '{"orders": []}'
28
+ end
29
+ B2W::Order.approved
30
+ end
31
+
32
+ it "accepts the purchase date" do
33
+ expect(RestClient::Request).to receive(:execute) do |params|
34
+ expect(params[:url]).to include("purchaseDate=2014-03-12")
35
+ '{"orders": []}'
36
+ end
37
+ B2W::Order.approved(purchase_date: '2014-03-12')
38
+ end
39
+ end
40
+
41
+ describe "#processing!" do
42
+ it "should update the order status as processing" do
43
+ orders = VCR.use_cassette('orders') { B2W::Order.all }
44
+ expect(RestClient::Request).to receive(:execute) do |params|
45
+ expect(params[:method]).to eql :put
46
+ expect(params[:headers][:content_type]).to eql 'application/json;charset=UTF-8'
47
+ expect(params[:payload]).to eql '{"status":"PROCESSING"}'
48
+ expect(params[:url]).to eql "#{@sandbox_endpoint}/order/67/status"
49
+ ""
50
+ end
51
+ orders.first.processing!
52
+ end
53
+ end
54
+
55
+ describe "#processing!" do
56
+ it "should update the order status as processing" do
57
+ orders = VCR.use_cassette('orders') { B2W::Order.all }
58
+ expect(RestClient::Request).to receive(:execute) do |params|
59
+ expect(params[:method]).to eql :put
60
+ expect(params[:headers][:content_type]).to eql 'application/json;charset=UTF-8'
61
+ expect(params[:payload]).to eql '{"status":"PROCESSING"}'
62
+ expect(params[:url]).to eql "#{@sandbox_endpoint}/order/67/status"
63
+ ""
64
+ end
65
+ orders.first.processing!
66
+ end
67
+ end
68
+
69
+ describe "#invoiced!" do
70
+ it "should update the order status as invoiced" do
71
+ expect(RestClient::Request).to receive(:execute) do |params|
72
+ expect(params[:method]).to eql :put
73
+ expect(params[:headers][:content_type]).to eql 'application/json;charset=UTF-8'
74
+ expect(params[:payload]).to eql "{\"status\":\"INVOICED\",\"invoiced\":{\"key\":\"123\",\"number\":\"456\",\"line\":\"789\",\"issueDate\":\"2014-01-31\"}}"
75
+ expect(params[:url]).to eql "#{@sandbox_endpoint}/order/67/status"
76
+ ""
77
+ end
78
+ B2W::Order.new('id' => 67).invoiced! key: "123", number: "456", line: "789", issueDate: "2014-01-31"
79
+ end
80
+ end
81
+
82
+ describe "#shipped!" do
83
+ it "should update the order status as shipped" do
84
+ expect(RestClient::Request).to receive(:execute) do |params|
85
+ expect(params[:method]).to eql :put
86
+ expect(params[:headers][:content_type]).to eql 'application/json;charset=UTF-8'
87
+ expect(params[:payload]).to eql "{\"status\":\"SHIPPED\",\"shipped\":{\"trackingProtocol\":\"123\",\"deliveredCarrierDate\":\"2013-12-31\",\"estimatedDelivery\":\"2014-01-31\"}}"
88
+ expect(params[:url]).to eql "#{@sandbox_endpoint}/order/67/status"
89
+ ""
90
+ end
91
+ B2W::Order.new('id' => 67).shipped! trackingProtocol: "123", deliveredCarrierDate: "2013-12-31", estimatedDelivery: "2014-01-31"
92
+ end
93
+ end
94
+
95
+ describe "#delivered!" do
96
+ it "should update the order status as delivered" do
97
+ expect(RestClient::Request).to receive(:execute) do |params|
98
+ expect(params[:method]).to eql :put
99
+ expect(params[:headers][:content_type]).to eql 'application/json;charset=UTF-8'
100
+ expect(params[:payload]).to eql "{\"status\":\"DELIVERED\",\"delivered\":{\"deliveredCustomDate\":\"2014-01-31\"}}"
101
+ expect(params[:url]).to eql "#{@sandbox_endpoint}/order/67/status"
102
+ ""
103
+ end
104
+ B2W::Order.new('id' => 67).delivered! deliveredCustomDate: "2014-01-31"
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+
3
+ describe B2W::Product do
4
+
5
+ before { @sandbox_endpoint = 'https://api-sandbox.bonmarketplace.com.br' }
6
+
7
+ describe ".create!" do
8
+ it "should persist a valid product" do
9
+ product = VCR.use_cassette('product_success') do
10
+ B2W::Product.create!(id: 'b2w-ruby-1', name: 'B2W Ruby', sku: [{ id: 'b2w-ruby-1', name: 'B2W Ruby', ean: ['9789896370107'], urlImage: ['http://imagens.isupply.com.br/436/web/9788539903436.jpg'], weight: 1, stockQuantity: 3, enable: true, price: { sellPrice: 10, listPrice: 10 }}], manufacturer: { name: 'Digital Pages', model: 'b2w-ruby', warrantyTime: 1 }, deliveryType: 'SHIPMENT', nbm: { number: '49019900', origin: '1' })
11
+ end
12
+ expect(product).to be_persisted
13
+ end
14
+
15
+ it "should not persist an invalid product" do
16
+ product = VCR.use_cassette('product_not_success') do
17
+ B2W::Product.create!(id: 'b2w-ruby-2', name: 'B2W Ruby', sku: [{ id: 'b2w-ruby-2', name: 'B2W Ruby', ean: ['invalid'], weight: 1, stockQuantity: 3, enable: true, price: { sellPrice: 10, listPrice: 10 }}], manufacturer: { name: 'Digital Pages', model: 'b2w-ruby', warrantyTime: 1 }, deliveryType: 'SHIPMENT', nbm: { number: '49019900', origin: '1' })
18
+ end
19
+ expect(product).to_not be_persisted
20
+ end
21
+ end
22
+
23
+ describe "#update!" do
24
+ it "should update a valid product" do
25
+ product = B2W::Product.new 'sku' => 'b2w-ruby-1'
26
+ VCR.use_cassette('product_update_true') do
27
+ expect(product.update!(id: 'b2w-ruby-1', name: 'B2W Ruby', ean: ['9789896370107'], urlImage: ['http://imagens.isupply.com.br/436/web/9788539903436.jpg'], weight: 1, stockQuantity: 3, enable: true, price: { sellPrice: 10, listPrice: 10 })).to be true
28
+ end
29
+ end
30
+
31
+ it "should not update an invalid product" do
32
+ product = B2W::Product.new 'sku' => 'invalid'
33
+ VCR.use_cassette('product_update_false') do
34
+ expect(product.update!(id: 'b2w-ruby-1', name: 'B2W Ruby', ean: ['9789896370107'], weight: 1, stockQuantity: 3, enable: true, price: { sellPrice: 10, listPrice: 10 })).to be false
35
+ end
36
+ end
37
+ end
38
+
39
+ describe "#update_price!" do
40
+ it "should update the prices" do
41
+ expect(RestClient::Request).to receive(:execute) do |params|
42
+ expect(params[:method]).to eql :put
43
+ expect(params[:headers][:content_type]).to eql 'application/json;charset=UTF-8'
44
+ expect(params[:payload]).to eql '{"sellPrice":11.14,"listPrice":12.34}'
45
+ expect(params[:url]).to eql "#{@sandbox_endpoint}/sku/b2w-ruby-1/price"
46
+ end
47
+ B2W::Product.new('sku' => 'b2w-ruby-1', 'sell_price' => 11.14, 'list_price' => 12.34).update_price!
48
+ end
49
+ end
50
+
51
+ describe "#update_stock!" do
52
+ it "should update the stock" do
53
+ expect(RestClient::Request).to receive(:execute) do |params|
54
+ expect(params[:method]).to eql :put
55
+ expect(params[:headers][:content_type]).to eql 'application/json;charset=UTF-8'
56
+ expect(params[:payload]).to eql '{"quantity":2}'
57
+ expect(params[:url]).to eql "#{@sandbox_endpoint}/sku/b2w-ruby-1/stock"
58
+ ""
59
+ end
60
+ B2W::Product.new('sku' => 'b2w-ruby-1', 'quantity' => 2).update_stock!
61
+ end
62
+ end
63
+
64
+ describe "#exists?" do
65
+ it "should return true if the sku exists" do
66
+ VCR.use_cassette('product_exists_true') do
67
+ expect(B2W::Product.new('sku' => 'b2w-ruby-1').exists?).to be true
68
+ end
69
+ end
70
+
71
+ it "should return false if the sku doesnt exists" do
72
+ VCR.use_cassette('product_exists_false') do
73
+ expect(B2W::Product.new('sku' => '0123').exists?).to be false
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'webmock'
4
+ require 'vcr'
5
+ require 'b2w'
6
+
7
+ VCR.configure do |c|
8
+ c.cassette_library_dir = 'spec/cassettes'
9
+ c.hook_into :webmock
10
+ end
11
+
12
+ RSpec.configure do |config|
13
+ end
14
+
15
+ B2W.config! token: File.read('spec/token').strip, sandbox: true
data/spec/token ADDED
@@ -0,0 +1 @@
1
+ A01D5EA1EE4A33E02C02939F4B0E15D3
metadata ADDED
@@ -0,0 +1,210 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: b2w
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Diego Carrion
8
+ - Wesley Conde
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-10-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rest-client
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.7'
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.7.2
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - "~>"
29
+ - !ruby/object:Gem::Version
30
+ version: '1.7'
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.7.2
34
+ - !ruby/object:Gem::Dependency
35
+ name: bundler
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ type: :development
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ - !ruby/object:Gem::Dependency
49
+ name: rake
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.4'
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: 10.4.2
58
+ type: :development
59
+ prerelease: false
60
+ version_requirements: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - "~>"
63
+ - !ruby/object:Gem::Version
64
+ version: '10.4'
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: 10.4.2
68
+ - !ruby/object:Gem::Dependency
69
+ name: rspec
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.1'
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: 3.1.0
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - "~>"
83
+ - !ruby/object:Gem::Version
84
+ version: '3.1'
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: 3.1.0
88
+ - !ruby/object:Gem::Dependency
89
+ name: webmock
90
+ requirement: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: '1.20'
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: 1.20.4
98
+ type: :development
99
+ prerelease: false
100
+ version_requirements: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '1.20'
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: 1.20.4
108
+ - !ruby/object:Gem::Dependency
109
+ name: vcr
110
+ requirement: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - "~>"
113
+ - !ruby/object:Gem::Version
114
+ version: '2.9'
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: 2.9.3
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '2.9'
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: 2.9.3
128
+ - !ruby/object:Gem::Dependency
129
+ name: pry
130
+ requirement: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - "~>"
133
+ - !ruby/object:Gem::Version
134
+ version: 0.10.1
135
+ type: :runtime
136
+ prerelease: false
137
+ version_requirements: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - "~>"
140
+ - !ruby/object:Gem::Version
141
+ version: 0.10.1
142
+ description: B2W Digital API
143
+ email:
144
+ - dc.rec1@gmail.com
145
+ - kerponeis@gmail.com
146
+ executables: []
147
+ extensions: []
148
+ extra_rdoc_files: []
149
+ files:
150
+ - ".gitignore"
151
+ - ".rspec"
152
+ - Gemfile
153
+ - LICENSE.txt
154
+ - README.md
155
+ - Rakefile
156
+ - b2w.gemspec
157
+ - lib/b2w.rb
158
+ - lib/b2w/base.rb
159
+ - lib/b2w/order.rb
160
+ - lib/b2w/product.rb
161
+ - lib/b2w/version.rb
162
+ - spec/cassettes/order.yml
163
+ - spec/cassettes/orders.yml
164
+ - spec/cassettes/product_exists_false.yml
165
+ - spec/cassettes/product_exists_true.yml
166
+ - spec/cassettes/product_not_success.yml
167
+ - spec/cassettes/product_success.yml
168
+ - spec/cassettes/product_update_false.yml
169
+ - spec/cassettes/product_update_true.yml
170
+ - spec/order_spec.rb
171
+ - spec/product_spec.rb
172
+ - spec/spec_helper.rb
173
+ - spec/token
174
+ homepage: https://www.github.com/wesleyskap/b2w-ruby
175
+ licenses:
176
+ - MIT
177
+ metadata: {}
178
+ post_install_message:
179
+ rdoc_options: []
180
+ require_paths:
181
+ - lib
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ required_rubygems_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ requirements: []
193
+ rubyforge_project:
194
+ rubygems_version: 2.4.8
195
+ signing_key:
196
+ specification_version: 4
197
+ summary: Ruby interface to B2W
198
+ test_files:
199
+ - spec/cassettes/order.yml
200
+ - spec/cassettes/orders.yml
201
+ - spec/cassettes/product_exists_false.yml
202
+ - spec/cassettes/product_exists_true.yml
203
+ - spec/cassettes/product_not_success.yml
204
+ - spec/cassettes/product_success.yml
205
+ - spec/cassettes/product_update_false.yml
206
+ - spec/cassettes/product_update_true.yml
207
+ - spec/order_spec.rb
208
+ - spec/product_spec.rb
209
+ - spec/spec_helper.rb
210
+ - spec/token