ship_station 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/console +13 -0
- data/lib/ship_station.rb +22 -0
- data/lib/ship_station/api.rb +20 -0
- data/lib/ship_station/api/carrier.rb +3 -0
- data/lib/ship_station/api/customer.rb +4 -0
- data/lib/ship_station/api/model.rb +8 -0
- data/lib/ship_station/api/order.rb +4 -0
- data/lib/ship_station/api/product.rb +3 -0
- data/lib/ship_station/api/shipment.rb +4 -0
- data/lib/ship_station/api/store.rb +3 -0
- data/lib/ship_station/api/tag.rb +3 -0
- data/lib/ship_station/api/warehouse.rb +3 -0
- data/lib/ship_station/base.rb +30 -0
- data/lib/ship_station/middleware.rb +34 -0
- data/lib/ship_station/version.rb +3 -0
- metadata +158 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8c000ebfd5f6604336805892caa3c352ff991fbc
|
4
|
+
data.tar.gz: 6864e83c629ff2a0f09ebd670912ea5b0aed249a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0baf0fcaa50f07964d04b239a8a7c48e48eecced627c4cf0e98eefa95543cf6fe7127c9405265ee1d948af8ee7433abf1f5ed34de171c51dbd7111b8e66817c6
|
7
|
+
data.tar.gz: da0302c83684aed39668821d2ccf4301d91d02d25eee831f096c13ed709e2d7b76f3e471402d2481a44c7e51cc25d39c1b8954f192eb124186aa34543b001bf3
|
data/bin/console
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$:.push File.expand_path("lib", __FILE__)
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
|
6
|
+
require "ship_station"
|
7
|
+
|
8
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
9
|
+
# with your gem easier. You can also use a different console, if you like.
|
10
|
+
|
11
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
12
|
+
require 'pry'
|
13
|
+
Pry.start
|
data/lib/ship_station.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# require 'ship_station/version'
|
2
|
+
require 'active_support'
|
3
|
+
require 'active_support/core_ext'
|
4
|
+
require 'active_support/dependencies'
|
5
|
+
require 'logger'
|
6
|
+
require 'her'
|
7
|
+
|
8
|
+
# App
|
9
|
+
require 'ship_station/base'
|
10
|
+
require 'ship_station/middleware'
|
11
|
+
require 'ship_station/api'
|
12
|
+
# Models
|
13
|
+
|
14
|
+
require 'ship_station/api/model'
|
15
|
+
require 'ship_station/api/carrier'
|
16
|
+
require 'ship_station/api/customer'
|
17
|
+
require 'ship_station/api/order'
|
18
|
+
require 'ship_station/api/product'
|
19
|
+
require 'ship_station/api/shipment'
|
20
|
+
require 'ship_station/api/store'
|
21
|
+
require 'ship_station/api/tag'
|
22
|
+
require 'ship_station/api/warehouse'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module ShipStation
|
2
|
+
module V1
|
3
|
+
API = Her::API.new
|
4
|
+
API.setup url: "https://ssapi.shipstation.com" do |c|
|
5
|
+
#Authentication
|
6
|
+
c.use Faraday::Request::BasicAuthentication, ShipStation.username, ShipStation.password
|
7
|
+
|
8
|
+
# Request
|
9
|
+
# c.use Faraday::Request::UrlEncoded
|
10
|
+
c.use ShipStation::Middleware::JSONRequest
|
11
|
+
|
12
|
+
# Response
|
13
|
+
# c.use Her::Middleware::DefaultParseJSON
|
14
|
+
c.use ShipStation::Middleware::ResponseParser
|
15
|
+
|
16
|
+
# Adapter
|
17
|
+
c.use Faraday::Adapter::NetHttp
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module ShipStation
|
2
|
+
class ShipstationError < StandardError; end
|
3
|
+
|
4
|
+
class AuthenticationError < ShipstationError; end
|
5
|
+
class ConfigurationError < ShipstationError; end
|
6
|
+
|
7
|
+
class << self
|
8
|
+
extend ActiveSupport::Autoload
|
9
|
+
|
10
|
+
attr_writer :username
|
11
|
+
attr_writer :password
|
12
|
+
|
13
|
+
attr_accessor :limit
|
14
|
+
attr_accessor :remaining
|
15
|
+
attr_accessor :reset
|
16
|
+
|
17
|
+
def username
|
18
|
+
@username ||= ENV["SHIPSTATION_API_KEY"] or
|
19
|
+
raise(ConfigurationError, "Shipstation username not configured")
|
20
|
+
end
|
21
|
+
|
22
|
+
def password
|
23
|
+
@password ||= ENV["SHIPSTATION_API_SECRET"] or
|
24
|
+
raise(ConfigurationError, "Shipstation password not configured")
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
SS = ShipStation
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module ShipStation
|
2
|
+
module Middleware
|
3
|
+
class ResponseParser < Her::Middleware::FirstLevelParseJSON
|
4
|
+
|
5
|
+
def on_complete(env)
|
6
|
+
ShipStation.limit = env.response.headers["x-rate-limit-limit"]
|
7
|
+
ShipStation.remaining = env.response.headers["x-rate-limit-remaining"]
|
8
|
+
ShipStation.reset = env.response.headers["x-rate-limit-reset"]
|
9
|
+
super(env)
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
# This middleware adds a "Content-Type: application/json" HTTP header
|
15
|
+
class JSONRequest < Faraday::Middleware
|
16
|
+
# @private
|
17
|
+
def add_header(headers)
|
18
|
+
headers.merge! "Content-Type" => "application/json"
|
19
|
+
end
|
20
|
+
|
21
|
+
# @private
|
22
|
+
def call(env)
|
23
|
+
puts "########Request Url############"
|
24
|
+
puts env.url
|
25
|
+
puts "###############################"
|
26
|
+
unless env.method == :get
|
27
|
+
env[:body] = encode env[:body] unless env[:body].respond_to?(:to_str)
|
28
|
+
end
|
29
|
+
@app.call(env)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ship_station
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Jacobs
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-10-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: launchy
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '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'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: her
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.10.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.10.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry-byebug
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '12.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '12.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: dotenv
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2.2'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2.2'
|
111
|
+
description: Shipstation API
|
112
|
+
email:
|
113
|
+
- benjaminpjacobs@gmail.com
|
114
|
+
executables:
|
115
|
+
- console
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- bin/console
|
120
|
+
- lib/ship_station.rb
|
121
|
+
- lib/ship_station/api.rb
|
122
|
+
- lib/ship_station/api/carrier.rb
|
123
|
+
- lib/ship_station/api/customer.rb
|
124
|
+
- lib/ship_station/api/model.rb
|
125
|
+
- lib/ship_station/api/order.rb
|
126
|
+
- lib/ship_station/api/product.rb
|
127
|
+
- lib/ship_station/api/shipment.rb
|
128
|
+
- lib/ship_station/api/store.rb
|
129
|
+
- lib/ship_station/api/tag.rb
|
130
|
+
- lib/ship_station/api/warehouse.rb
|
131
|
+
- lib/ship_station/base.rb
|
132
|
+
- lib/ship_station/middleware.rb
|
133
|
+
- lib/ship_station/version.rb
|
134
|
+
homepage:
|
135
|
+
licenses: []
|
136
|
+
metadata:
|
137
|
+
allowed_push_host: https://rubygems.org
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '2.2'
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
requirements: []
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 2.6.14.1
|
155
|
+
signing_key:
|
156
|
+
specification_version: 4
|
157
|
+
summary: Shipstation API
|
158
|
+
test_files: []
|