shipit_api 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,117 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.shipit.cl/v/skus
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ X-Shipit-Email:
11
+ - staff@shipit.cl
12
+ X-Shipit-Access-Token:
13
+ - v8fH62dPTULmrAEXxhzB
14
+ Content-Type:
15
+ - application/json
16
+ Accept:
17
+ - application/vnd.shipit.v2
18
+ Accept-Encoding:
19
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
20
+ User-Agent:
21
+ - Ruby
22
+ response:
23
+ status:
24
+ code: 200
25
+ message: OK
26
+ headers:
27
+ Server:
28
+ - nginx/1.10.3 (Ubuntu)
29
+ Date:
30
+ - Tue, 20 Mar 2018 15:50:53 GMT
31
+ Content-Type:
32
+ - application/json; charset=utf-8
33
+ Connection:
34
+ - close
35
+ X-Frame-Options:
36
+ - SAMEORIGIN
37
+ X-Xss-Protection:
38
+ - 1; mode=block
39
+ X-Content-Type-Options:
40
+ - nosniff
41
+ Etag:
42
+ - W/"b7b2d21d09aef9c935f0720acde6495d"
43
+ Cache-Control:
44
+ - max-age=0, private, must-revalidate
45
+ X-Request-Id:
46
+ - 77cec413-51ce-4098-9db4-f799c80a49b8
47
+ X-Runtime:
48
+ - '0.040512'
49
+ body:
50
+ encoding: UTF-8
51
+ string: '[{"id":3998,"name":"SKU-011","amount":3,"min_amount":20,"company_id":1,"position":null,"description":"SKU-ENVIOS-assaS","created_at":"2017-02-22T10:36:57.162-03:00","updated_at":"2017-12-27T13:01:14.938-03:00","warehouse_id":2,"width":10.0,"length":10.0,"height":10.0,"weight":0.5,"ws_amount":0,"ws_updated_at":null},{"id":7202,"name":"tst-hirp-22","amount":11776,"min_amount":5,"company_id":1,"position":null,"description":"tst-hirp-22","created_at":"2017-11-27T10:48:05.100-03:00","updated_at":"2018-02-06T12:05:55.460-03:00","warehouse_id":1,"width":22.0,"length":22.0,"height":22.0,"weight":2.0,"ws_amount":0,"ws_updated_at":null},{"id":7070,"name":"1-TEST
52
+ 8000","amount":8724,"min_amount":450,"company_id":1,"position":null,"description":null,"created_at":"2017-10-31T20:14:45.053-03:00","updated_at":"2018-01-05T13:53:36.609-03:00","warehouse_id":1,"width":10.0,"length":10.0,"height":10.0,"weight":1.0,"ws_amount":0,"ws_updated_at":null},{"id":9265,"name":"BOB1","amount":12,"min_amount":1,"company_id":1,"position":null,"description":"SKU
53
+ de prueba","created_at":"2018-03-15T11:01:37.739-03:00","updated_at":"2018-03-15T11:01:37.739-03:00","warehouse_id":1,"width":10.0,"length":10.0,"height":30.0,"weight":1.0,"ws_amount":0,"ws_updated_at":null},{"id":9266,"name":"BOB2","amount":6,"min_amount":2,"company_id":1,"position":null,"description":"BOB
54
+ Prueba 2","created_at":"2018-03-15T11:53:42.082-03:00","updated_at":"2018-03-15T11:53:42.082-03:00","warehouse_id":2,"width":10.0,"length":11.0,"height":9.0,"weight":1.2,"ws_amount":0,"ws_updated_at":null},{"id":9267,"name":"BOB3","amount":7,"min_amount":3,"company_id":1,"position":null,"description":"BOB
55
+ Prueba 3","created_at":"2018-03-15T11:53:42.093-03:00","updated_at":"2018-03-15T11:53:42.093-03:00","warehouse_id":2,"width":11.0,"length":12.0,"height":10.0,"weight":1.3,"ws_amount":0,"ws_updated_at":null},{"id":9268,"name":"BOB4","amount":8,"min_amount":4,"company_id":1,"position":null,"description":"BOB
56
+ Prueba 4","created_at":"2018-03-15T11:53:42.103-03:00","updated_at":"2018-03-15T11:53:42.103-03:00","warehouse_id":2,"width":12.0,"length":13.0,"height":11.0,"weight":1.4,"ws_amount":0,"ws_updated_at":null},{"id":9269,"name":"BOB5","amount":9,"min_amount":5,"company_id":1,"position":null,"description":"BOB
57
+ Prueba 5","created_at":"2018-03-15T11:53:42.113-03:00","updated_at":"2018-03-15T11:53:42.113-03:00","warehouse_id":2,"width":13.0,"length":14.0,"height":12.0,"weight":1.5,"ws_amount":0,"ws_updated_at":null},{"id":9272,"name":"BOB8","amount":12,"min_amount":8,"company_id":1,"position":null,"description":"BOB
58
+ Prueba 8","created_at":"2018-03-15T11:53:42.142-03:00","updated_at":"2018-03-15T11:53:42.142-03:00","warehouse_id":2,"width":16.0,"length":17.0,"height":15.0,"weight":1.8,"ws_amount":0,"ws_updated_at":null},{"id":9270,"name":"BOB6","amount":10,"min_amount":6,"company_id":1,"position":null,"description":"BOB
59
+ Prueba 6","created_at":"2018-03-15T11:53:42.122-03:00","updated_at":"2018-03-15T11:53:42.122-03:00","warehouse_id":2,"width":14.0,"length":15.0,"height":13.0,"weight":1.6,"ws_amount":0,"ws_updated_at":null},{"id":9271,"name":"BOB7","amount":11,"min_amount":7,"company_id":1,"position":null,"description":"BOB
60
+ Prueba 7","created_at":"2018-03-15T11:53:42.132-03:00","updated_at":"2018-03-15T11:53:42.132-03:00","warehouse_id":2,"width":15.0,"length":16.0,"height":14.0,"weight":1.7,"ws_amount":0,"ws_updated_at":null},{"id":9273,"name":"BOB9","amount":13,"min_amount":9,"company_id":1,"position":null,"description":"BOB
61
+ Prueba 9","created_at":"2018-03-15T11:53:42.151-03:00","updated_at":"2018-03-15T11:53:42.151-03:00","warehouse_id":2,"width":17.0,"length":18.0,"height":16.0,"weight":1.9,"ws_amount":0,"ws_updated_at":null},{"id":7116,"name":"rqetwerwef","amount":22,"min_amount":0,"company_id":1,"position":null,"description":null,"created_at":"2017-11-21T12:20:24.986-03:00","updated_at":"2017-11-21T12:20:24.986-03:00","warehouse_id":1,"width":10.0,"length":10.0,"height":10.0,"weight":2.0,"ws_amount":0,"ws_updated_at":null},{"id":7117,"name":"wqefasdfsd","amount":2286,"min_amount":69,"company_id":1,"position":null,"description":null,"created_at":"2017-11-21T12:21:13.125-03:00","updated_at":"2018-02-06T15:59:52.173-03:00","warehouse_id":1,"width":20.0,"length":30.0,"height":20.0,"weight":1.0,"ws_amount":0,"ws_updated_at":null},{"id":7118,"name":"efwrfsdf","amount":2301,"min_amount":0,"company_id":1,"position":null,"description":null,"created_at":"2017-11-21T12:22:51.060-03:00","updated_at":"2017-11-21T12:22:51.060-03:00","warehouse_id":1,"width":2.0,"length":2.0,"height":2.0,"weight":1.0,"ws_amount":0,"ws_updated_at":null},{"id":7115,"name":"hiro","amount":290,"min_amount":0,"company_id":1,"position":null,"description":null,"created_at":"2017-11-21T12:19:58.340-03:00","updated_at":"2017-11-21T12:19:58.340-03:00","warehouse_id":1,"width":10.0,"length":10.0,"height":10.0,"weight":5.0,"ws_amount":0,"ws_updated_at":null},{"id":7119,"name":"treretert","amount":318,"min_amount":0,"company_id":1,"position":null,"description":"ewwedfxdfd","created_at":"2017-11-21T12:31:34.679-03:00","updated_at":"2017-11-21T12:31:34.679-03:00","warehouse_id":1,"width":30.0,"length":30.0,"height":30.0,"weight":3.0,"ws_amount":0,"ws_updated_at":null},{"id":7120,"name":"wetrtwertwertwertwertwerdfsdg","amount":444,"min_amount":0,"company_id":1,"position":null,"description":"4twererwer","created_at":"2017-11-21T12:43:29.008-03:00","updated_at":"2017-11-21T12:43:29.008-03:00","warehouse_id":1,"width":44.0,"length":44.0,"height":44.0,"weight":4.0,"ws_amount":0,"ws_updated_at":null},{"id":7071,"name":"1-1-TEST
62
+ 8000","amount":2998,"min_amount":257,"company_id":1,"position":null,"description":null,"created_at":"2017-11-02T07:43:41.748-03:00","updated_at":"2018-03-07T16:29:33.534-03:00","warehouse_id":1,"width":10.0,"length":10.0,"height":10.0,"weight":1.0,"ws_amount":0,"ws_updated_at":null},{"id":9175,"name":"CMA03-test","amount":4,"min_amount":1,"company_id":1,"position":null,"description":"Collar
63
+ Beagle","created_at":"2018-03-06T17:44:32.914-03:00","updated_at":"2018-03-06T17:44:32.914-03:00","warehouse_id":2,"width":8.0,"length":2.0,"height":10.0,"weight":0.1,"ws_amount":0,"ws_updated_at":null},{"id":9224,"name":"Test-asd-1","amount":1,"min_amount":1,"company_id":1,"position":null,"description":"qweqwe","created_at":"2018-03-08T15:46:42.572-03:00","updated_at":"2018-03-08T15:46:42.572-03:00","warehouse_id":2,"width":12.0,"length":12.0,"height":12.0,"weight":1.0,"ws_amount":0,"ws_updated_at":null}]'
64
+ http_version:
65
+ recorded_at: Tue, 20 Mar 2018 15:50:54 GMT
66
+ - request:
67
+ method: get
68
+ uri: https://api.shipit.cl/v/skus/3998
69
+ body:
70
+ encoding: US-ASCII
71
+ string: ''
72
+ headers:
73
+ X-Shipit-Email:
74
+ - staff@shipit.cl
75
+ X-Shipit-Access-Token:
76
+ - v8fH62dPTULmrAEXxhzB
77
+ Content-Type:
78
+ - application/json
79
+ Accept:
80
+ - application/vnd.shipit.v2
81
+ Accept-Encoding:
82
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
83
+ User-Agent:
84
+ - Ruby
85
+ response:
86
+ status:
87
+ code: 200
88
+ message: OK
89
+ headers:
90
+ Server:
91
+ - nginx/1.10.3 (Ubuntu)
92
+ Date:
93
+ - Tue, 20 Mar 2018 15:51:07 GMT
94
+ Content-Type:
95
+ - application/json; charset=utf-8
96
+ Connection:
97
+ - close
98
+ X-Frame-Options:
99
+ - SAMEORIGIN
100
+ X-Xss-Protection:
101
+ - 1; mode=block
102
+ X-Content-Type-Options:
103
+ - nosniff
104
+ Etag:
105
+ - W/"343c110da207c39a38bca52e56643a66"
106
+ Cache-Control:
107
+ - max-age=0, private, must-revalidate
108
+ X-Request-Id:
109
+ - e89e608d-d438-43fd-aded-2807d52ae266
110
+ X-Runtime:
111
+ - '0.025513'
112
+ body:
113
+ encoding: UTF-8
114
+ string: '{"id":3998,"name":"SKU-011","amount":3,"min_amount":20,"company_id":1,"position":null,"description":"SKU-ENVIOS-assaS","created_at":"2017-02-22T10:36:57.162-03:00","updated_at":"2017-12-27T13:01:14.938-03:00","warehouse_id":2,"width":10.0,"length":10.0,"height":10.0,"weight":0.5,"ws_amount":0,"ws_updated_at":null}'
115
+ http_version:
116
+ recorded_at: Tue, 20 Mar 2018 15:51:07 GMT
117
+ recorded_with: VCR 4.0.0
data/lib/shipit_api.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'json'
2
+ require 'faraday'
3
+ require 'active_support/inflector'
4
+ require 'pry'
5
+ require 'shipit_api/config'
6
+ require 'shipit_api/version'
7
+ require 'shipit_api/base'
8
+ require 'shipit_api/session'
9
+ require 'shipit_api/package'
10
+ require 'shipit_api/commune'
11
+ require 'shipit_api/sku'
12
+ require 'shipit_api/quotation'
13
+ require 'shipit_api/setting'
14
+
15
+ module ShipitAPI
16
+ end
File without changes
@@ -0,0 +1,27 @@
1
+ module ShipitAPI
2
+ class Commune
3
+ def self.find(opts = {})
4
+ new().find(opts)
5
+ end
6
+
7
+ def self.all(opts = {})
8
+ new(opts).all
9
+ end
10
+
11
+ def initialize(opts = {})
12
+ @opts = opts
13
+ @api_call = ShipitAPI::Session.connection(self.class.name)
14
+ end
15
+
16
+ def all
17
+ response = @api_call.get('', @opts)
18
+ JSON.parse(response.body)
19
+ end
20
+
21
+ def find(opts = {})
22
+ opts = opts.empty? ? StandardError : opts
23
+ response = @api_call.get("#{opts[:id]}")
24
+ JSON.parse(response.body)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,39 @@
1
+ module ShipitAPI
2
+ class Config
3
+ BASE_URL = 'https://api.shipit.cl/v/'.freeze
4
+ EXTENSION = '.json'.freeze
5
+ CONTENT_TYPE = 'application/json'.freeze
6
+ ACCEPT = 'application/vnd.shipit.v'.freeze
7
+
8
+ attr_accessor :x_shipit_email, :x_shipit_access_token, :content_type, :version,
9
+ :base_url, :accept, :headers
10
+
11
+ def self.settings(version = 2)
12
+ puts "VERSION: #{version}"
13
+ @settings ||= Config.new(version)
14
+ @settings.set_version!(version)
15
+ end
16
+
17
+ def self.setup(&block)
18
+ yield(settings) if block_given?
19
+ end
20
+
21
+ def initialize(version)
22
+ @extension = EXTENSION
23
+ @content_type = CONTENT_TYPE
24
+ @version = version
25
+ @base_url = BASE_URL
26
+ @accept = "#{ACCEPT}#{version}"
27
+ end
28
+
29
+ def set_version!(version)
30
+ self.version = version
31
+ self.accept = "#{ACCEPT}#{version}"
32
+ self
33
+ end
34
+
35
+ def headers
36
+ { 'X-Shipit-Email' => @x_shipit_email, 'X-Shipit-Access-Token' => @x_shipit_access_token, 'Content-Type' => @content_type, 'Accept' => @accept }
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,81 @@
1
+ module ShipitAPI
2
+ class Package
3
+ def self.all(opts = {})
4
+ new(opts).all
5
+ end
6
+
7
+ def self.create(opts = {})
8
+ new(opts).save
9
+ end
10
+
11
+ def self.find(opts = {})
12
+ new().find(opts)
13
+ end
14
+
15
+ def self.latest
16
+ new().latest
17
+ end
18
+
19
+ def initialize(opts = {})
20
+ @opts = opts
21
+ @api_call = ShipitAPI::Session.connection(self.class.name)
22
+ build!
23
+ end
24
+
25
+ def attrs
26
+ { reference: "", full_name: "", email: "", items_count: 1, cellphone: "", is_payable: false, packing: "Sin Empaque",
27
+ shipping_type: "Normal", destiny: "Domicilio", courier_for_client: nil, address_attributes: address_attrs, with_purchase_insurance: false, purchase: purchase_attrs,
28
+ inventory_activity: fulfillment_attrs }
29
+ end
30
+
31
+ def address_attrs
32
+ { commune_id: nil, street: "", number: "", complement: "" }
33
+ end
34
+
35
+ def purchase_attrs
36
+ { detail: "Ropa", ticket_number: 11111111, amount: 0, extra_insurance: false }
37
+ end
38
+
39
+ def fulfillment_attrs
40
+ { inventory_activity_orders_attributes: [] }
41
+ end
42
+
43
+ def sku_attrs
44
+ { sku_id: nil, amount: 1 }
45
+ end
46
+
47
+ def build!
48
+ @opts.each do |k,v|
49
+ singleton_class.send(:attr_accessor, k)
50
+ instance_variable_set("@#{k}", v)
51
+ end
52
+ end
53
+
54
+ def all
55
+ @opts = @opts.empty? ? { year: Time.now.year, month: Time.now.month } : @opts
56
+ response = @api_call.get('', @opts)
57
+ JSON.parse(response.body, symbolize_names: true)
58
+ end
59
+
60
+ def find(opts = opts)
61
+ opts = opts.empty? ? StandardError : opts
62
+ response = @api_call.get("#{opts[:id]}")
63
+ JSON.parse(response.body, symbolize_names: true)
64
+ end
65
+
66
+ def save
67
+ @opts = @opts.empty? ? StandardError : @opts
68
+ response = @api_call.post('',@opts.to_json)
69
+ JSON.parse(response.body, symbolize_names: true)
70
+ end
71
+
72
+ def destroy
73
+ end
74
+
75
+ def latest
76
+ @opts = @opts.empty? ? { year: Time.now.year, month: Time.now.month } : @opts
77
+ response = @api_call.get('', @opts)
78
+ JSON.parse(response.body, symbolize_names: true).last
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,30 @@
1
+ module ShipitAPI
2
+ class Quotation
3
+ def self.get_prices(opts = {})
4
+ new(opts).get_prices
5
+ end
6
+
7
+ def initialize(opts = {})
8
+ @opts = opts
9
+ @api_call = ShipitAPI::Session.connection('prices', 3)
10
+ build!
11
+ end
12
+
13
+ def get_prices
14
+ package = { package: @opts }
15
+ response = @api_call.post('', package.to_json)
16
+ JSON.parse(response.body, symbolize_names: true)
17
+ end
18
+
19
+ def quotaiton_attrs
20
+ { width: 10, length: 10, height: 10, weight: 1, destinty: 'Domicilio' }
21
+ end
22
+
23
+ def build!
24
+ @opts.each do |k,v|
25
+ singleton_class.send(:attr_accessor, k)
26
+ instance_variable_set("@#{k}", v)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,11 @@
1
+ module ShipitAPI
2
+ class Session
3
+ def self.connection(name, version=2)
4
+ name = name.split("::").last.pluralize.downcase
5
+ endpoint = "#{Config.settings.base_url}#{name}"
6
+ connection = Faraday.new(endpoint)
7
+ connection.headers = Config.settings(version).headers
8
+ connection
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,36 @@
1
+ module ShipitAPI
2
+ class Setting
3
+
4
+ def self.info(opts = {})
5
+ end
6
+
7
+ def self.save(opts = {})
8
+ new(opts).save
9
+ end
10
+
11
+ def initialize(opts = {})
12
+ @opts = opts
13
+ @api_call = ShipitAPI::Session.connection(self.class.name)
14
+ end
15
+
16
+ def info
17
+ response = @api_call.get('', @opts)
18
+ JSON.parse(response.body, symbolize_names: true)
19
+ end
20
+
21
+ def save(opts = {})
22
+ set_hash!
23
+ @opts = @opts.empty? ? StandarError : @opts
24
+ end
25
+
26
+ private
27
+
28
+ attr_accessor :data
29
+
30
+ def set_hash!
31
+ response = info
32
+ data = response["configuration"]["pp"]["packages_webhook_url"] =
33
+ binding.pry
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,27 @@
1
+ module ShipitAPI
2
+ class Sku
3
+ def self.find(opts = {})
4
+ new().find(opts)
5
+ end
6
+
7
+ def self.all(opts = {})
8
+ new(opts).all
9
+ end
10
+
11
+ def initialize(opts = {})
12
+ @opts = opts
13
+ @api_call = ShipitAPI::Session.connection(self.class.name)
14
+ end
15
+
16
+ def all
17
+ response = @api_call.get('', @opts)
18
+ JSON.parse(response.body)
19
+ end
20
+
21
+ def find(opts = {})
22
+ opts = opts.empty? ? StandardError : opts
23
+ response = @api_call.get("#{opts[:id]}")
24
+ JSON.parse(response.body, symbolize_names: true)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module ShipitAPI
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,45 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "shipit_api/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "shipit_api"
8
+ spec.version = ShipitAPI::VERSION
9
+ spec.authors = ["Nelson Patricio Jimenez"]
10
+ spec.email = ["developer.jimenez@gmail.com"]
11
+
12
+ spec.summary = %q{ShipitAPI is a lightweight gem for accessing the Shipit REST web services}
13
+ spec.description = %q{ShipitAPI is a lightweight gem for accessing the Shipit REST web services}
14
+ spec.homepage = "https://developers.shipit.cl/v1.0/reference"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_dependency "faraday", '~> 0.9'
34
+ spec.add_dependency "uri_template", '~> 0.7'
35
+ spec.add_dependency "activesupport"
36
+
37
+ spec.add_development_dependency "pry-byebug"
38
+ spec.add_development_dependency "webmock"
39
+ spec.add_development_dependency "vcr"
40
+ spec.add_development_dependency "turn"
41
+ spec.add_development_dependency "bundler", "~> 1.16"
42
+ spec.add_development_dependency "rake", "~> 10.0"
43
+ spec.add_development_dependency "rspec", "~> 3.0"
44
+ spec.add_development_dependency "capybara"
45
+ end