shipstation-rb 0.0.5

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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 448a9a4571dcb325ba5f8fada723744c1a6a8931
4
+ data.tar.gz: b863c8faf50e9710192dd03f0d1a8897256c103b
5
+ SHA512:
6
+ metadata.gz: 9131e977ec1a89341ad758a7f441b57cc71f80381a034ceb33ecc69b02abdc175a2c92c6712906644d823b7c7819c69ef4c425dc796445c826ba49efa720a2f3
7
+ data.tar.gz: 252017f623c8a0a2d1d97d09a12e88565fc34b3cd1e78f853f979dd513ed64642723c640da4223c6850b68ec8ba41a8887cd6269ce4a28c8331eee74d3dc0fb1
@@ -0,0 +1,20 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile ~/.gitignore_global
6
+
7
+ # Ignore bundler config
8
+ /.bundle
9
+
10
+ # Ignore the default SQLite database.
11
+ /db/*.sqlite3
12
+
13
+ # Ignore all logfiles and tempfiles.
14
+ /log/*.log
15
+ /tmp
16
+ /solr/data/development/index
17
+
18
+ # Ignore all VCR fixtures
19
+ /spec/fixtures/
20
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,61 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ shipstation-ruby (0.0.2)
5
+ rash (= 0.4.0)
6
+ ruby_odata (= 0.1.6)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (4.0.5)
12
+ i18n (~> 0.6, >= 0.6.9)
13
+ minitest (~> 4.2)
14
+ multi_json (~> 1.3)
15
+ thread_safe (~> 0.1)
16
+ tzinfo (~> 0.3.37)
17
+ addressable (2.3.6)
18
+ ansi (1.4.3)
19
+ crack (0.4.2)
20
+ safe_yaml (~> 1.0.0)
21
+ hashie (2.0.5)
22
+ i18n (0.6.9)
23
+ mime-types (2.3)
24
+ mini_portile (0.6.0)
25
+ minitest (4.7.5)
26
+ multi_json (1.10.1)
27
+ nokogiri (1.6.2.1)
28
+ mini_portile (= 0.6.0)
29
+ rake (10.3.2)
30
+ rash (0.4.0)
31
+ hashie (~> 2.0.0)
32
+ rest-client (1.6.7)
33
+ mime-types (>= 1.16)
34
+ ruby_odata (0.1.6)
35
+ activesupport (>= 3.0.0)
36
+ addressable (>= 2.3.4)
37
+ i18n (~> 0.6.0)
38
+ nokogiri (>= 1.4.2)
39
+ rest-client (>= 1.5.1)
40
+ safe_yaml (1.0.3)
41
+ thread_safe (0.3.4)
42
+ turn (0.9.7)
43
+ ansi
44
+ minitest (~> 4)
45
+ tzinfo (0.3.39)
46
+ vcr (2.9.2)
47
+ webmock (1.18.0)
48
+ addressable (>= 2.3.6)
49
+ crack (>= 0.3.2)
50
+
51
+ PLATFORMS
52
+ ruby
53
+
54
+ DEPENDENCIES
55
+ bundler (= 1.3.5)
56
+ minitest (~> 4.2)
57
+ rake
58
+ shipstation-ruby!
59
+ turn
60
+ vcr
61
+ webmock
@@ -0,0 +1,162 @@
1
+ shipstation-ruby
2
+ ================
3
+
4
+ This is a Ruby wrapper for [ShipStation](http://www.shipstation.com/)'s [OData API](http://api.shipstation.com/MainPage.ashx).
5
+
6
+ ## 0.0.1 Features
7
+ [here](https://github.com/codyduval/shipstation-ruby)
8
+
9
+ ## 0.0.2 Features
10
+
11
+ * Support spacename, You can use it with rails model Order and SS::Order. `SS` is default namespace.
12
+ * Support api host
13
+ * Collection Create
14
+
15
+ ## 0.0.3 Features
16
+
17
+ * Collection Update
18
+ * Collection Delete( set attr Active = false )
19
+ * Collection Destroy( call `delete_object` )
20
+
21
+ ## 0.0.4 Features
22
+
23
+ * Collection First
24
+ * Collection Last
25
+ * Collection Count
26
+ * Collection return Rash instance
27
+ * Collection Create return a instance, not Array.
28
+ * Collection Where by array
29
+ * Collection Where by String. eg. `client.orders.where("CreateDate ge datetime'2014-06-17'")`
30
+ You can write a filter string, read more [here](http://msdn.microsoft.com/en-us/library/ff478141.aspx), [here](http://www.odata.org/documentation/odata-version-3-0/odata-version-3-0-core-protocol), and [here](http://docs.oasis-open.org/odata/odata/v4.0/os/part1-protocol/odata-v4.0-os-part1-protocol.html#_Built-in_Query_Functions)
31
+ * Test with shipstation api 1.3
32
+
33
+ ## 0.0.5 Features
34
+
35
+ Rename the gem to shipstation-rb.
36
+
37
+
38
+ ## Installation
39
+
40
+ ``` ruby
41
+ gem 'shipstation-rb', '~> 0.0.4'
42
+ gem 'awesome_print', :require => 'ap'
43
+ ```
44
+
45
+ ## Rails Configuration
46
+
47
+ The ShipStation API uses basic HTTP authentication. Inside config/initializers, create a new configuration file and use the following template to pass in your ShipStation credentials:
48
+
49
+ ``` ruby
50
+ ShipStation.username = ENV['SHIPSTATION_USERNAME']
51
+ ShipStation.password = ENV['SHIPSTATION_PASSWORD']
52
+ ShipStation.api_host = ENV['SHIPSTATION_API_HOST']
53
+ ```
54
+
55
+ OR
56
+
57
+ ```ruby
58
+ require "shipstation"
59
+ client = ShipStation::Client.new(APICONFIG[:ship_station_api], APICONFIG[:ship_station_account], APICONFIG[:ship_station_password])
60
+ ```
61
+
62
+ ## Usage
63
+
64
+ ### Set your credentials and create a new client:
65
+ ``` ruby
66
+ ShipStation.api_host = "https://data.shipstation.com/1.3"
67
+ ShipStation.password = "shipstation_password"
68
+ ShipStation.password = "shipstation_password"
69
+ client = ShipStation::Client.new
70
+ ```
71
+
72
+ ### Or create a new client by passing credentials directly:
73
+ ``` ruby
74
+ client = ShipStation::Client.new("https://data.shipstation.com/1.3", "username", "password")
75
+ ```
76
+
77
+ ### Query a resource by record id:
78
+ ``` ruby
79
+ order = client.order.find(12345)
80
+ ```
81
+
82
+ ### Get all records for any given resource in an array (paginated in batches of 100):
83
+ ``` ruby
84
+ orders = client.order.all
85
+ ```
86
+
87
+ ### Query records for any resource by any attribute, returns an array:
88
+ ``` ruby
89
+ open_texas_orders = client.order.where("active" => "true", "ship_state" => "TX")
90
+ ```
91
+
92
+ ### Other resources follow a similar pattern
93
+ ``` ruby
94
+ all_warehouses = client.warehouse.all
95
+ customer_12345 = client.customer.find(12345)
96
+ texas_fedex_shipments = client.shipment.where("shipping_service_id" => 0001, "state" => "TX")
97
+ ```
98
+ etc.
99
+
100
+ ### Once returned, resources can be queried by field name
101
+ ``` ruby
102
+ client = ShipStation::Client.new
103
+ order = client.order.find(12345)
104
+
105
+ order.order_id ## 12345
106
+ order.ship_city ## Boise
107
+ order.order_total ## $343.32
108
+ ```
109
+
110
+ ### Create order
111
+ ```ruby
112
+ client = ShipStation::Client.new
113
+ client.order.create(OrderNumber: "T0001", OrderStatusID: 2)
114
+ ```
115
+
116
+ ### Update order
117
+ ```ruby
118
+ client = ShipStation::Client.new
119
+ client.order.Update(1234, OrderNumber: "T0002", OrderStatusID: 2)
120
+ ```
121
+
122
+ ### Delete order
123
+ ```ruby
124
+ client = ShipStation::Client.new
125
+ client.orders.delete(1234) #=> order.active = false
126
+ ```
127
+
128
+ ### Destory order
129
+ ```ruby
130
+ client = ShipStation::Client.new
131
+ client.orders.destory(1234) # svc.delete_object(klass)
132
+ ```
133
+
134
+ ### List all stores
135
+ ```ruby
136
+ client = ShipStation::Client.new
137
+ client.stores.all
138
+ ```
139
+
140
+ ### First of clollection
141
+ ```ruby
142
+ client = ShipStation::Client.new
143
+ client.stores.first
144
+ ```
145
+
146
+ ### Last of clollection
147
+ ```ruby
148
+ client = ShipStation::Client.new
149
+ client.stores.last
150
+ ```
151
+
152
+ ## Requirements
153
+ This gem has been tested on Ruby 1.9.3 on version 1.1 of ShipStation's API.(by author)
154
+ This gem has been tested on Ruby ruby-2.0.0-p247 on version 1.2 and 1.3 of ShipStation's API.(By Rique Li)
155
+
156
+ ## About This Gem
157
+
158
+ I am Rique Li, I fork this from [shipstation-ruby](https://github.com/codyduval/shipstation-ruby/) and make some changes, when all test done, I will make a PR.
159
+
160
+ If You like this gem, write me. ^_^
161
+
162
+
@@ -0,0 +1,14 @@
1
+ require 'rake/testtask'
2
+ require "bundler/gem_tasks"
3
+
4
+ desc "Open an irb session preloaded with this library"
5
+ task :console do
6
+ sh "irb -rubygems -I lib -I extra -r shipstation.rb"
7
+ end
8
+
9
+ Rake::TestTask.new do |t|
10
+ t.test_files = FileList['spec/lib/shipstation/*_spec.rb']
11
+ t.verbose = true
12
+ end
13
+
14
+ task :default => :test
@@ -0,0 +1,15 @@
1
+ require "rash"
2
+ require "ruby_odata"
3
+
4
+ require "shipstation/client"
5
+ require "shipstation/collection"
6
+ require "shipstation/version"
7
+
8
+ module ShipStation
9
+
10
+ class ShipStationError < StandardError; end
11
+ class AuthenticationError < ShipStationError; end
12
+ class ConfigurationError < ShipStationError; end
13
+ class QueryError < ShipStationError; end
14
+
15
+ end
@@ -0,0 +1,31 @@
1
+ module ShipStation
2
+ class Client
3
+ attr_accessor :auth, :client, :namespace
4
+
5
+ # require "shipstation"
6
+ # client = ShipStation::Client.new(APICONFIG[:ship_station_api], APICONFIG[:ship_station_account], APICONFIG[:ship_station_password])
7
+ def initialize(api_host, username, password, namespace = "SS")
8
+ raise ArgumentError unless username && password && api_host
9
+ @auth = {:username => username, :password => password, :namespace => namespace}
10
+ @client = OData::Service.new(api_host, @auth)
11
+ @namespace = namespace
12
+ end
13
+
14
+ # client.orders.all
15
+ # client.ShippingProviders.all
16
+ # client.stores.all
17
+ # client.orders.create(OrderNumber: "Test0001", OrderStatusID; 2)
18
+ # client.orders.where("CreateDate ge datetime'2014-06-17'")
19
+ def method_missing(method, *args, &block)
20
+ method = method.to_s
21
+ options = args.last.is_a?(Hash) ? args.pop : {}
22
+ klass = method.pluralize.camelize
23
+ ShipStation::Collection.new(@client, klass, @namespace)
24
+ end
25
+
26
+ def inspect
27
+ "#<ShipStation::Client:#{object_id}>"
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,115 @@
1
+ module ShipStation
2
+ class Collection
3
+
4
+ attr_accessor :client, :klass, :namespace
5
+
6
+ def initialize(client, klass, namespace)
7
+ @client = client
8
+ @klass = klass
9
+ @namespace = namespace
10
+ end
11
+
12
+ def find(id)
13
+ @client.send("#{@klass}", id)
14
+ result = @client.execute.first
15
+ hashie_object(result)
16
+ end
17
+
18
+ def all
19
+ @client.send("#{@klass}")
20
+ results = @client.execute
21
+ results.map{|rrr| hashie_object(rrr) }
22
+ end
23
+
24
+ # filter
25
+ # http://msdn.microsoft.com/en-us/library/ff478141.aspx
26
+ # http://www.odata.org/documentation/odata-version-3-0/odata-version-3-0-core-protocol
27
+ # http://docs.oasis-open.org/odata/odata/v4.0/os/part1-protocol/odata-v4.0-os-part1-protocol.html#_Built-in_Query_Functions
28
+ def where(query)
29
+ if query.is_a?(Hash)
30
+ query_string = ""
31
+ query_array = []
32
+ query.each do |key, val|
33
+ # shipstation_style_attribute = attribute.to_s.classify.gsub(/Id/, 'ID')
34
+ if val.is_a?(Integer)
35
+ filter_string = "#{key} eq #{val}"
36
+ elsif val.is_a?(String)
37
+ filter_string = "#{key} eq '#{val}'"
38
+ else
39
+ raise ShipStation::QueryError, "Query value incorrect."
40
+ end
41
+ query_array << filter_string
42
+ end
43
+ query_string = query_array.join(' and ')
44
+ elsif query.is_a?(String)
45
+ query_string = query
46
+ else
47
+ raise ShipStation::QueryError, "Query incorrect."
48
+ end
49
+ @client.send("#{@klass}").filter("#{query_string}")
50
+ results = @client.execute
51
+ results.map{|rrr| hashie_object(rrr) }
52
+ end
53
+
54
+ def first
55
+ @client.send("#{@klass}").send("order_by", "CreateDate asc").send("top", 1)
56
+ result = @client.execute.first
57
+ hashie_object(result)
58
+ end
59
+
60
+ def last
61
+ @client.send("#{@klass}").send("order_by", "CreateDate desc").send("top", 1)
62
+ result = @client.execute.first
63
+ hashie_object(result)
64
+ end
65
+
66
+ def count
67
+ @client.send("#{@klass}").send("count")
68
+ @client.execute
69
+ end
70
+
71
+ # client.order.create(OrderNumber: "HAHA1111", OrderStatusID: 2)
72
+ def create(attrs={})
73
+ klazz = "#{@namespace}::#{@klass.singularize}".constantize.new
74
+ attrs.each do |key, val|
75
+ klazz.send("#{key.to_s}=", val)
76
+ end
77
+ @client.send("AddTo#{@klass}", klazz)
78
+ result = @client.send("save_changes").first
79
+ hashie_object(result)
80
+ end
81
+
82
+ # client.orders.update(43478396, OrderNumber: "HAHA1111")
83
+ def update(id, attrs={})
84
+ @client.send("#{@klass}", id)
85
+ klazz = @client.execute.last
86
+ attrs.each do |key, val|
87
+ klazz.send("#{key.to_s}=", val)
88
+ end
89
+ @client.send("update_object", klazz)
90
+ @client.send("save_changes")
91
+ end
92
+
93
+ # client.orders.delete(123)
94
+ def delete(id)
95
+ update(id, {active: false})
96
+ end
97
+
98
+ # client.orders.destroy(123)
99
+ def destroy(id)
100
+ @client.send("#{@klass}", id)
101
+ klazz = @client.execute.last
102
+ @client.send("delete_object", klazz)
103
+ @client.send("save_changes")
104
+ end
105
+
106
+ private
107
+
108
+ def hashie_object(result)
109
+ return if result.nil?
110
+ result_hash = JSON.parse(result.to_json)
111
+ Hashie::Rash.new(result_hash)
112
+ end
113
+
114
+ end
115
+ end
@@ -0,0 +1,3 @@
1
+ module ShipStation
2
+ VERSION = "0.0.5"
3
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "shipstation/version"
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "shipstation-rb"
8
+ gem.version = ShipStation::VERSION
9
+ gem.licenses = 'MIT'
10
+ gem.authors = ["Rique Li"]
11
+ gem.email = ["hi@liwei.me"]
12
+ gem.description = 'An API wrapper for the ShipStation API.base on Cody Duval\'s 0.0.1'
13
+ gem.summary = 'Ruby wrapper ShipStation API'
14
+ gem.homepage = 'https://github.com/liwei78/shipstation-ruby'
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_dependency 'rash', '0.4.0'
22
+ gem.add_dependency 'ruby_odata', '0.1.6'
23
+ gem.add_development_dependency 'minitest', '~> 4.2'
24
+ gem.add_development_dependency 'turn', '~> 0.9'
25
+ gem.add_development_dependency 'rake', '~> 10.3'
26
+ gem.add_development_dependency 'vcr', '~> 2.9'
27
+ gem.add_development_dependency 'webmock', '~> 1.18'
28
+ gem.add_development_dependency 'bundler', '1.3.5'
29
+ end
metadata ADDED
@@ -0,0 +1,166 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shipstation-rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: ruby
6
+ authors:
7
+ - Rique Li
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rash
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.4.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.4.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: ruby_odata
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.6
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.6
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '4.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '4.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: turn
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '0.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '10.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '10.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '2.9'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '2.9'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: '1.18'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '1.18'
111
+ - !ruby/object:Gem::Dependency
112
+ name: bundler
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: 1.3.5
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: 1.3.5
125
+ description: An API wrapper for the ShipStation API.base on Cody Duval's 0.0.1
126
+ email:
127
+ - hi@liwei.me
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - .gitignore
133
+ - Gemfile
134
+ - Gemfile.lock
135
+ - README.md
136
+ - Rakefile
137
+ - lib/shipstation.rb
138
+ - lib/shipstation/client.rb
139
+ - lib/shipstation/collection.rb
140
+ - lib/shipstation/version.rb
141
+ - shipstation.gemspec
142
+ homepage: https://github.com/liwei78/shipstation-ruby
143
+ licenses:
144
+ - MIT
145
+ metadata: {}
146
+ post_install_message:
147
+ rdoc_options: []
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ required_rubygems_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ requirements: []
161
+ rubyforge_project:
162
+ rubygems_version: 2.2.0
163
+ signing_key:
164
+ specification_version: 4
165
+ summary: Ruby wrapper ShipStation API
166
+ test_files: []