ship_hero 0.1.2

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.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +5 -0
  5. data/Gemfile +6 -0
  6. data/Gemfile.lock +56 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +39 -0
  9. data/Rakefile +6 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/lib/ship_hero.rb +57 -0
  13. data/lib/ship_hero/api.rb +59 -0
  14. data/lib/ship_hero/exceptions/service_exception.rb +11 -0
  15. data/lib/ship_hero/models/base.rb +13 -0
  16. data/lib/ship_hero/models/image.rb +6 -0
  17. data/lib/ship_hero/models/order.rb +22 -0
  18. data/lib/ship_hero/models/order_history.rb +7 -0
  19. data/lib/ship_hero/models/order_line_item.rb +16 -0
  20. data/lib/ship_hero/models/order_line_item_product_shot.rb +6 -0
  21. data/lib/ship_hero/models/order_note.rb +6 -0
  22. data/lib/ship_hero/models/order_shipping_address.rb +16 -0
  23. data/lib/ship_hero/models/order_shipping_lines.rb +8 -0
  24. data/lib/ship_hero/models/product.rb +21 -0
  25. data/lib/ship_hero/models/product_variant.rb +20 -0
  26. data/lib/ship_hero/models/requests/get_order.rb +8 -0
  27. data/lib/ship_hero/models/requests/get_orders.rb +11 -0
  28. data/lib/ship_hero/models/requests/get_product.rb +9 -0
  29. data/lib/ship_hero/models/requests/get_shipment.rb +10 -0
  30. data/lib/ship_hero/models/responses/create_order.rb +9 -0
  31. data/lib/ship_hero/models/responses/error.rb +4 -0
  32. data/lib/ship_hero/models/responses/general.rb +11 -0
  33. data/lib/ship_hero/models/responses/get_order.rb +10 -0
  34. data/lib/ship_hero/models/responses/get_webhooks.rb +10 -0
  35. data/lib/ship_hero/models/shipment.rb +9 -0
  36. data/lib/ship_hero/models/webhook.rb +9 -0
  37. data/lib/ship_hero/services/base_service.rb +90 -0
  38. data/lib/ship_hero/services/order_service.rb +36 -0
  39. data/lib/ship_hero/services/product_service.rb +21 -0
  40. data/lib/ship_hero/services/shipment_service.rb +21 -0
  41. data/lib/ship_hero/services/webhook_service.rb +25 -0
  42. data/lib/ship_hero/util/config.rb +81 -0
  43. data/lib/ship_hero/util/helpers.rb +44 -0
  44. data/lib/ship_hero/version.rb +3 -0
  45. data/ship_hero.gemspec +34 -0
  46. metadata +211 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 110a9abe4cc19477e7a0239aa11711d73a16f1ba96eff67bc39050bbd1a1c85d
4
+ data.tar.gz: 69b1eda95a8413f8a0c238aa091faf6178b23e6d78095c3843ab6b6026125db0
5
+ SHA512:
6
+ metadata.gz: 9e2e99bc0b9255400eb8c9887eb6f5be586921786e5e0e33255791e2194915ff6943761d04719b22affee12564df8114ad6afd50c69d4f7ce80efa57425f420c
7
+ data.tar.gz: 29bb465391ec4b1802bfd6f5e2ec20e6423ca699d6414468d344049494381fe2822d0221fff8c8e1e1a12ecfcacf47dbbb4543c2873aab05d393747a9a4bda85
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.3
5
+ before_install: gem install bundler -v 1.16.0
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in ship_hero.gemspec
6
+ gemspec
@@ -0,0 +1,56 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ship_hero (0.1.1)
5
+ hashie (>= 1.2.0, < 4.0)
6
+ json (~> 1.8, >= 1.8.1)
7
+ mime-types (>= 1.25.1, < 4.0)
8
+ rest-client (>= 1.6.7, < 4.0)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ diff-lcs (1.3)
14
+ domain_name (0.5.20180417)
15
+ unf (>= 0.0.5, < 1.0.0)
16
+ hashie (3.6.0)
17
+ http-cookie (1.0.3)
18
+ domain_name (~> 0.5)
19
+ json (1.8.6)
20
+ mime-types (3.2.2)
21
+ mime-types-data (~> 3.2015)
22
+ mime-types-data (3.2019.0331)
23
+ netrc (0.11.0)
24
+ rake (10.5.0)
25
+ rest-client (2.0.2)
26
+ http-cookie (>= 1.0.2, < 2.0)
27
+ mime-types (>= 1.16, < 4.0)
28
+ netrc (~> 0.8)
29
+ rspec (3.7.0)
30
+ rspec-core (~> 3.7.0)
31
+ rspec-expectations (~> 3.7.0)
32
+ rspec-mocks (~> 3.7.0)
33
+ rspec-core (3.7.1)
34
+ rspec-support (~> 3.7.0)
35
+ rspec-expectations (3.7.0)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.7.0)
38
+ rspec-mocks (3.7.0)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.7.0)
41
+ rspec-support (3.7.1)
42
+ unf (0.1.4)
43
+ unf_ext
44
+ unf_ext (0.0.7.6)
45
+
46
+ PLATFORMS
47
+ ruby
48
+
49
+ DEPENDENCIES
50
+ bundler (~> 1.16)
51
+ rake (~> 10.0)
52
+ rspec (~> 3.0)
53
+ ship_hero!
54
+
55
+ BUNDLED WITH
56
+ 1.17.3
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Kyle Schutt
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ # ShipHero
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ship_hero`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ship_hero'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ship_hero
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ship_hero.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ship_hero"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,57 @@
1
+ require "ship_hero/version"
2
+ require 'rubygems'
3
+ require 'rest_client'
4
+ require 'json'
5
+ require 'hashie'
6
+ require 'openssl'
7
+ require 'base64'
8
+
9
+ module ShipHero
10
+ autoload :Api, 'ship_hero/api'
11
+ autoload :VERSION, 'ship_hero/version'
12
+
13
+ # Models
14
+ autoload :Base, 'ship_hero/models/base'
15
+ autoload :Image, 'ship_hero/models/image'
16
+ autoload :Product, 'ship_hero/models/product'
17
+ autoload :ProductVariant, 'ship_hero/models/product_variant'
18
+ autoload :Order, 'ship_hero/models/order'
19
+ autoload :OrderHistory, 'ship_hero/models/order_history'
20
+ autoload :OrderLineItem, 'ship_hero/models/order_line_item'
21
+ autoload :OrderLineItemProductShot, 'ship_hero/models/order_line_item_product_shot'
22
+ autoload :OrderNote, 'ship_hero/models/order_note'
23
+ autoload :OrderShippingAddress, 'ship_hero/models/order_shipping_address'
24
+ autoload :OrderShippingLines, 'ship_hero/models/order_shipping_lines'
25
+ autoload :Webhook, 'ship_hero/models/webhook'
26
+
27
+ module Services
28
+ autoload :BaseService, 'ship_hero/services/base_service'
29
+ autoload :OrderService, 'ship_hero/services/order_service'
30
+ autoload :ProductService, 'ship_hero/services/product_service'
31
+ autoload :ShipmentService, 'ship_hero/services/shipment_service'
32
+ autoload :WebhookService, 'ship_hero/services/webhook_service'
33
+ end
34
+
35
+ module Responses
36
+ autoload :General, 'ship_hero/models/responses/general'
37
+ autoload :CreateOrder, 'ship_hero/models/responses/create_order'
38
+ autoload :GetOrder, 'ship_hero/models/responses/get_order'
39
+ autoload :GetWebhooks, 'ship_hero/models/responses/get_webhooks'
40
+ end
41
+
42
+ module Requests
43
+ autoload :GetOrder, 'ship_hero/models/requests/get_order'
44
+ autoload :GetOrders, 'ship_hero/models/requests/get_orders'
45
+ autoload :GetProduct, 'ship_hero/models/requests/get_product'
46
+ autoload :GetShipment, 'ship_hero/models/requests/get_shipment'
47
+ end
48
+
49
+ module Util
50
+ autoload :Config, 'ship_hero/util/config'
51
+ autoload :Helpers, 'ship_hero/util/helpers'
52
+ end
53
+
54
+ module Exceptions
55
+ autoload :ServiceException, 'ship_hero/exceptions/service_exception'
56
+ end
57
+ end
@@ -0,0 +1,59 @@
1
+ #
2
+ # api.rb
3
+ # ShipHero
4
+ #
5
+ # Copyright (c) 2018 Kyle Schutt. All rights reserved.
6
+
7
+ module ShipHero
8
+ class Api
9
+ attr_accessor :api_key
10
+
11
+ def initialize(api_key)
12
+ @api_key = api_key
13
+ end
14
+
15
+ # Product Services
16
+ def get_products(request)
17
+ ShipHero::Services::ProductService.new(@api_key).get_products(request)
18
+ end
19
+ def create_product(request)
20
+ ShipHero::Services::ProductService.new(@api_key).create_product(request)
21
+ end
22
+
23
+ # Order Services
24
+ def get_orders(request)
25
+ ShipHero::Services::OrderService.new(@api_key).get_orders(request)
26
+ end
27
+ def get_order(request)
28
+ ShipHero::Services::OrderService.new(@api_key).get_order(request)
29
+ end
30
+ def create_order(request)
31
+ ShipHero::Services::OrderService.new(@api_key).create_order(request)
32
+ end
33
+ def update_order(request)
34
+ ShipHero::Services::OrderService.new(@api_key).update_order(request)
35
+ end
36
+ def create_order_historye(request)
37
+ ShipHero::Services::OrderService.new(@api_key).create_order_historye(request)
38
+ end
39
+
40
+ # Shipment Services
41
+ def get_shipments(request)
42
+ ShipHero::Services::ShipmentService.new(@api_key).get_shipments(request)
43
+ end
44
+ def create_shipment(request)
45
+ ShipHero::Services::ShipmentService.new(@api_key).create_shipment(request)
46
+ end
47
+
48
+ # Webhook Services
49
+ def get_webhooks
50
+ ShipHero::Services::WebhookService.new(@api_key).get_webhooks
51
+ end
52
+ def register_webhook(request)
53
+ ShipHero::Services::WebhookService.new(@api_key).register_webhook(request)
54
+ end
55
+ def unregister_webhook(request)
56
+ ShipHero::Services::WebhookService.new(@api_key).unregister_webhook(request)
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,11 @@
1
+ #
2
+ # service_exception.rb
3
+ # ShipHero
4
+ #
5
+ # Copyright (c) 2018 Kyle Schutt. All rights reserved.
6
+
7
+ module ShipHero
8
+ module Exceptions
9
+ class ServiceException < Exception; end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ module ShipHero
2
+ class Base < Hashie::Dash
3
+ include Hashie::Extensions::Dash::Coercion
4
+ include Hashie::Extensions::Dash::PropertyTranslation
5
+
6
+ property :token, coerce: String
7
+
8
+ def initialize(hash = {})
9
+ # ensure we symbolize keys
10
+ super(Hashie.symbolize_keys!(hash))
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ module ShipHero
2
+ class Image < ShipHero::Base
3
+ property :src, coerce: String, required: true
4
+ property :position, coerce: Integer
5
+ end
6
+ end
@@ -0,0 +1,22 @@
1
+ module ShipHero
2
+ class Order < ShipHero::Base
3
+ property :email, coerce: String
4
+ property :total_tax, coerce: String
5
+ property :order_id, coerce: String
6
+ property :profile, coerce: String
7
+ property :subtotal_price, coerce: String
8
+ property :created_at, coerce: String
9
+ property :fulfillment_status, coerce: String
10
+ property :required_ship_date, coerce: String
11
+ property :total_discounts, coerce: String
12
+ property :total_price, coerce: String
13
+ property :default_warehouse, coerce: String
14
+
15
+ property :line_items, coerce: Array[ShipHero::OrderLineItem]
16
+ property :shipping_lines, coerce: ShipHero::OrderShippingLines
17
+ property :note_attributes, coerce: ShipHero::OrderNote
18
+ property :shipping_address, coerce: ShipHero::OrderShippingAddress
19
+ property :billing_address, coerce: ShipHero::OrderShippingAddress
20
+ property :tags, coerce: Array[String]
21
+ end
22
+ end
@@ -0,0 +1,7 @@
1
+ module ShipHero
2
+ class OrderHistory < ShipHero::Base
3
+ property :order_id, coerce: Integer
4
+ property :username, coerce: String, default: '-1'
5
+ property :information, coerce: String
6
+ end
7
+ end
@@ -0,0 +1,16 @@
1
+ module ShipHero
2
+ class OrderLineItem < ShipHero::Base
3
+ property :sku, coerce: String
4
+ property :name, coerce: String
5
+ property :title, coerce: String
6
+ property :price, coerce: String
7
+ property :barcode, coerce: String
8
+ property :variant_title, coerce: String
9
+ property :quantity, coerce: String
10
+ property :id, coerce: String
11
+ property :product_id, coerce: String
12
+ property :default_warehouse, coerce: String
13
+
14
+ property :product_shots, coerce: Array[ShipHero::OrderLineItemProductShot]
15
+ end
16
+ end
@@ -0,0 +1,6 @@
1
+ module ShipHero
2
+ class OrderLineItemProductShot < ShipHero::Base
3
+ property :url, coerce: String
4
+ property :sort, coerce: String
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module ShipHero
2
+ class OrderNote < ShipHero::Base
3
+ property :name, coerce: String
4
+ property :value, coerce: String
5
+ end
6
+ end
@@ -0,0 +1,16 @@
1
+ module ShipHero
2
+ class OrderShippingAddress < ShipHero::Base
3
+ property :province, coerce: String
4
+ property :city, coerce: String
5
+ property :first_name, coerce: String
6
+ property :last_name, coerce: String
7
+ property :zip, coerce: String
8
+ property :province_code, coerce: String
9
+ property :country, coerce: String
10
+ property :company, coerce: String
11
+ property :phone, coerce: String
12
+ property :country_code, coerce: String
13
+ property :address1, coerce: String
14
+ property :address2, coerce: String
15
+ end
16
+ end
@@ -0,0 +1,8 @@
1
+ module ShipHero
2
+ class OrderShippingLines < ShipHero::Base
3
+ property :title, coerce: String
4
+ property :price, coerce: String
5
+ property :method, coerce: String
6
+ # property :carrier, coerce: String
7
+ end
8
+ end
@@ -0,0 +1,21 @@
1
+ module ShipHero
2
+ class Product < ShipHero::Base
3
+ property :title, coerce: String, required: true
4
+ property :brand, coerce: String
5
+ property :sku, coerce: String, required: true
6
+ property :type, coerce: String, default: :configurable
7
+ property :warehouse, coerce: String
8
+ property :tariff_code, coerce: String
9
+ property :customs_description, coerce: String
10
+
11
+ property :available_inventory, coerce: Integer
12
+
13
+ property :price, coerce: Float
14
+ property :customs_value, coerce: Float
15
+
16
+ coerce_key :track_inventory, ->(v){ Util::Helpers.to_bool(v) }
17
+
18
+ property :images, coerce: Array[Image], required: true
19
+ property :variants, coerce: Array[ProductVariant]
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ module ShipHero
2
+ class ProductVariant < ShipHero::Base
3
+ property :sku, coerce: String, required: true
4
+ property :parent_sku, coerce: String
5
+ property :title, coerce: String, required: true
6
+ property :available_inventory, coerce: Integer
7
+ property :bin, coerce: String
8
+ property :barcode, coerce: Integer
9
+ property :price, coerce: Float, required: true
10
+ property :value, coerce: Float
11
+ property :customs_value, coerce: String
12
+ property :customs_description, coerce: String
13
+ property :height, coerce: String
14
+ property :width, coerce: String
15
+ property :length, coerce: String
16
+ property :weight, coerce: String
17
+
18
+ property :images, coerce: Array[Image], required: true
19
+ end
20
+ end
@@ -0,0 +1,8 @@
1
+ module ShipHero
2
+ module Requests
3
+ class GetOrder < ShipHero::Base
4
+ property :id, coerce: String
5
+ property :order_number, coerce: String
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ module ShipHero
2
+ module Requests
3
+ class GetOrders < ShipHero::Base
4
+ property :page, coerce: String
5
+ property :from, coerce: String
6
+ property :to, coerce: String
7
+ property :all_orders, coerce: Integer
8
+ property :warehouse_id, coerce: Integer
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ module ShipHero
2
+ module Requests
3
+ class GetProduct < ShipHero::Base
4
+ property :sku, coerce: String
5
+ property :page, coerce: Integer
6
+ property :count, coerce: Integer
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ module ShipHero
2
+ module Requests
3
+ class GetShipment < ShipHero::Base
4
+ property :page, coerce: String
5
+ property :from, coerce: String
6
+ property :to, coerce: String
7
+ property :filter_on, coerce: String, default: 'order' # also allows `shipment`
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ module ShipHero
2
+ module Responses
3
+ class CreateOrder < ShipHero::Base
4
+ property :order_id, coerce: String
5
+ property :message, coerce: String
6
+ property :response, coerce: ShipHero::Order
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ module ShipHero
2
+ class Error < Hashie::Mash
3
+ end
4
+ end
@@ -0,0 +1,11 @@
1
+ module ShipHero
2
+ module Responses
3
+ class General < ShipHero::Base
4
+ property :status
5
+ property :code
6
+ property :results
7
+ property :Message, coerce: String
8
+ property :message, coerce: String
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ module ShipHero
2
+ module Responses
3
+ class GetOrder < ShipHero::Base
4
+ property :Message
5
+ property :message, coerce: String
6
+ property :code
7
+ property :orders
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module ShipHero
2
+ module Responses
3
+ class GetWebhooks < ShipHero::Base
4
+ property :code
5
+ property :Message, coerce: String
6
+ property :message, coerce: String
7
+ property :webhooks, coerce: Array[ShipHero::Webhook]
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ module ShipHero
2
+ class Shipment < ShipHero::Base
3
+ property :warehouse, coerce: String, required: true
4
+ property :profile, coerce: String, required: true
5
+
6
+ property :create_shipment, coerce: Integer, default: 0
7
+ property :notify_customer_via_store, coerce: Integer, default: 0
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module ShipHero
2
+ class Webhook < ShipHero::Base
3
+ # Options: Inventory Update , Shipment Update , Order Canceled , Capture Payment , PO Update , Return Update
4
+ property :name, coerce: String
5
+ property :url, coerce: String
6
+ # Options: shopify , magento , bigcommerce , amazon , ebay , api (for custom integrations) , Manuel Order , woocommerce , mystoreno , walmart , etsy
7
+ property :source, coerce: String
8
+ end
9
+ end
@@ -0,0 +1,90 @@
1
+ #
2
+ # ShipHero
3
+ #
4
+ # Copyright (c) 2018 Kyle Schutt. All rights reserved.
5
+
6
+ module ShipHero
7
+ module Services
8
+ class BaseService
9
+ attr_accessor :api_key
10
+
11
+ def initialize(api_key)
12
+ @api_key = api_key
13
+ end
14
+
15
+ protected
16
+
17
+ def get(path, params = {}, response_type = ShipHero::Responses::General)
18
+ url = URI::join(Util::Config.get('endpoints.base_url'), path).to_s
19
+ url = build_url(url, params)
20
+ response = RestClient.get(url, get_headers())
21
+ begin
22
+ response_type.new JSON.parse(response.body)
23
+ rescue
24
+ Hashie::Mash.new JSON.parse(response.body)
25
+ end
26
+ end
27
+
28
+ def post(path, body = {}, params = {}, response_type = ShipHero::Responses::General)
29
+ url = URI::join(Util::Config.get('endpoints.base_url'), path).to_s
30
+ url = build_url(url, params)
31
+ if body.is_a?(Hash)
32
+ body[:token] = @api_key
33
+ elsif body.is_a?(Array)
34
+ body.each do |m|
35
+ if m.is_a?(Hash)
36
+ m[:token] = @api_key
37
+ end
38
+ end
39
+ end
40
+ response = begin
41
+ RestClient.post(url, body.to_h.to_json, get_headers())
42
+ rescue => e
43
+ e.try(:response)
44
+ end
45
+
46
+ begin
47
+ response_type.new JSON.parse(response.body)
48
+ rescue
49
+ Hashie::Mash.new JSON.parse(response.body)
50
+ end
51
+ end
52
+
53
+ # Return required headers for making an http request with Iterable
54
+ # @param [String] content_type - The MIME type of the body of the request, default is 'application/json'
55
+ # @return [Hash] - authorization headers
56
+ def get_headers(content_type = 'application/json')
57
+ {
58
+ :content_type => content_type,
59
+ :accept => 'application/json',
60
+ :user_agent => "ShipHero Ruby SDK v#{ShipHero::VERSION} (#{RUBY_DESCRIPTION})",
61
+ :x_ctct_request_source => "sdk.ruby.#{ShipHero::VERSION}",
62
+ 'x-api-key' => @api_key
63
+ }
64
+ end
65
+
66
+ # Build a url from the base url and query parameters hash. Query parameters
67
+ # should not be URL encoded because this method will handle that
68
+ # @param [String] url - The base url
69
+ # @param [Hash] params - A hash with query parameters
70
+ # @return [String] - the url with query parameters hash
71
+ def build_url(url, params = nil)
72
+ if params.respond_to? :each
73
+ params.each do |key, value|
74
+ # Convert dates to CC date format
75
+ if value.respond_to? :iso8601
76
+ params[key] = value.iso8601
77
+ end
78
+
79
+ if key.to_s == 'next' && value.match(/^.*?next=(.*)$/)
80
+ params[key] = $1
81
+ end
82
+ end
83
+ else
84
+ params ||= {}
85
+ end
86
+ url + '?token=' + api_key + '&' + Util::Helpers.http_build_query(params)
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,36 @@
1
+ #
2
+ # order_service.rb
3
+ # ShipHero
4
+ #
5
+ # Copyright (c) 2017 Kyle Schutt. All rights reserved.
6
+
7
+ module ShipHero
8
+ module Services
9
+ class OrderService < BaseService
10
+ def get_orders(request = ShipHero::Requests::GetOrders.new)
11
+ raise Exceptions::ServiceException, "Must be a ShipHero::Requests::GetOrders" unless request.is_a?(ShipHero::Requests::GetOrders)
12
+ get(Util::Config.get('endpoints.get_orders'), request, ShipHero::Responses::GetOrder)
13
+ end
14
+
15
+ def get_order(request = ShipHero::Requests::GetOrder.new)
16
+ raise Exceptions::ServiceException, "Must be a ShipHero::Requests::GetOrder" unless request.is_a?(ShipHero::Requests::GetOrder)
17
+ get(Util::Config.get('endpoints.get_order'), request, ShipHero::Responses::GetOrder)
18
+ end
19
+
20
+ def create_order(request)
21
+ raise Exceptions::ServiceException, "Must be a ShipHero::Order" unless request.is_a?(ShipHero::Order)
22
+ post(Util::Config.get('endpoints.create_order'), request, nil, ShipHero::Responses::CreateOrder)
23
+ end
24
+
25
+ def update_order(request)
26
+ raise Exceptions::ServiceException, "Must be a ShipHero::Order" unless request.is_a?(ShipHero::Order)
27
+ post(Util::Config.get('endpoints.update_order'), request)
28
+ end
29
+
30
+ def create_order_history(request)
31
+ raise Exceptions::ServiceException, "Must be a ShipHero::OrderHistory" unless request.is_a?(ShipHero::OrderHistory)
32
+ post(Util::Config.get('endpoints.create_order_history'), request)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,21 @@
1
+ #
2
+ # product_service.rb
3
+ # ShipHero
4
+ #
5
+ # Copyright (c) 2018 Kyle Schutt. All rights reserved.
6
+
7
+ module ShipHero
8
+ module Services
9
+ class ProductService < BaseService
10
+ def get_products(request = ShipHero::Requests::GetProduct.new)
11
+ raise Exceptions::ServiceException, "Must be a ShipHero::Requests::GetProduct" unless request.is_a?(ShipHero::Requests::GetProduct)
12
+ get(Util::Config.get('endpoints.get_products'), request)
13
+ end
14
+
15
+ def create_product(product)
16
+ raise Exceptions::ServiceException, "Must be a ShipHero::Product" unless product.is_a?(ShipHero::Product)
17
+ post(Util::Config.get('endpoints.create_product'), [product])
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ #
2
+ # shipment_service.rb
3
+ # ShipHero
4
+ #
5
+ # Copyright (c) 2017 Kyle Schutt. All rights reserved.
6
+
7
+ module ShipHero
8
+ module Services
9
+ class ShipmentService < BaseService
10
+ def get_shipments(request = ShipHero::Requests::GetShipment.new)
11
+ raise Exceptions::ServiceException, "Must be a ShipHero::Requests::GetShipment" unless request.is_a?(ShipHero::Requests::GetShipment)
12
+ get(Util::Config.get('endpoints.get_shipments'), request)
13
+ end
14
+
15
+ def create_shipment(shipment)
16
+ raise Exceptions::ServiceException, "Must be a ShipHero::Shipment" unless shipment.is_a?(ShipHero::Shipment)
17
+ post(Util::Config.get('endpoints.create_shipment'), shipment)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ #
2
+ # webhook_service.rb
3
+ # ShipHero
4
+ #
5
+ # Copyright (c) 2017 Kyle Schutt. All rights reserved.
6
+
7
+ module ShipHero
8
+ module Services
9
+ class WebhookService < BaseService
10
+ def get_webhooks()
11
+ get(Util::Config.get('endpoints.get_webhooks'), nil, ShipHero::Responses::GetWebhooks)
12
+ end
13
+
14
+ def register_webhook(request)
15
+ raise Exceptions::ServiceException, "Must be a ShipHero::Webhook" unless request.is_a?(ShipHero::Webhook)
16
+ post(Util::Config.get('endpoints.register_webhook'), request)
17
+ end
18
+
19
+ def unregister_webhook(request)
20
+ raise Exceptions::ServiceException, "Must be a ShipHero::Webhook" unless request.is_a?(ShipHero::Webhook)
21
+ post(Util::Config.get('endpoints.unregister_webhook'), request)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,81 @@
1
+ #
2
+ # config.rb
3
+ # ShipHero
4
+ #
5
+ # Copyright (c) 2018 Kyle Schutt. All rights reserved.
6
+
7
+ module ShipHero
8
+ module Util
9
+ class Config
10
+
11
+ # Return a hash of configuration strings
12
+ # @return [Hash] - hash of configuration properties
13
+ @props = {
14
+ # REST endpoints
15
+ :endpoints => {
16
+ :base_url => 'https://api-gateway.shiphero.com/v1.2/general-api/',
17
+
18
+ # products
19
+ :get_products => 'get-product',
20
+ :create_product => 'product-creation',
21
+
22
+ # orders
23
+ :get_orders => 'get-orders',
24
+ :get_order => 'get-order',
25
+ :create_order => 'order-creation',
26
+ :update_order => 'order-update',
27
+ :create_order_history => 'order-history-creation',
28
+
29
+ # shipments
30
+ :get_shipments => 'get-shipments',
31
+ :create_shipment => 'shipment-creation',
32
+
33
+ # webhooks
34
+ :get_webhooks => 'get-webhooks',
35
+ :register_webhook => 'register-webhook',
36
+ :unregister_webhook => 'unregister-webhook',
37
+ },
38
+
39
+ # Authorization related configuration options
40
+ :auth => {
41
+ :api_key => ''
42
+ },
43
+
44
+ # Errors to be returned for various exceptions
45
+ :errors => {
46
+ :api_key_missing => 'api_key required either explicitly or in configuration.',
47
+ }
48
+ }
49
+
50
+ class << self
51
+ attr_accessor :props
52
+
53
+ def configure
54
+ yield props if block_given?
55
+ end
56
+
57
+ # Get a configuration property given a specified location, example usage: Config::get('auth.token_endpoint')
58
+ # @param [String] index - location of the property to obtain
59
+ # @return [String]
60
+ def get(index)
61
+ properties = index.split('.')
62
+ get_value(properties, props)
63
+ end
64
+
65
+ private
66
+
67
+ # Navigate through a config array looking for a particular index
68
+ # @param [Array] index The index sequence we are navigating down
69
+ # @param [Hash, String] value The portion of the config array to process
70
+ # @return [String]
71
+ def get_value(index, value)
72
+ index = index.is_a?(Array) ? index : [index]
73
+ key = index.shift.to_sym
74
+ value.is_a?(Hash) and value[key] and value[key].is_a?(Hash) ?
75
+ get_value(index, value[key]) :
76
+ value[key]
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,44 @@
1
+ #
2
+ # helpers.rb
3
+ # ShipHero
4
+ #
5
+ # Copyright (c) 2018 Kyle Schutt. All rights reserved.
6
+
7
+ module ShipHero
8
+ module Util
9
+ class Helpers
10
+ class << self
11
+
12
+ # Build the HTTP query from the given parameters
13
+ # @param [Hash] params
14
+ # @return [String] query string
15
+ def http_build_query(params)
16
+ params.collect{ |k,v| "#{k}=#{encode(v)}" }.reverse.join('&')
17
+ end
18
+
19
+ # Escape special characters
20
+ # @param [String] str
21
+ def encode(str)
22
+ CGI.escape(str).gsub('.', '%2E').gsub('-', '%2D')
23
+ end
24
+
25
+ # String to bool
26
+ # @param [String] str
27
+ def to_bool(str)
28
+ return true if str == true || str =~ (/(true|t|yes|y|1)$/i)
29
+ return false if str == false || str == nil || str == '' || str =~ (/(false|f|no|n|0)$/i)
30
+ end
31
+
32
+ # String to DateTime
33
+ # @param [String] str
34
+ def to_date_time(str)
35
+ begin
36
+ Time.parse(str)
37
+ rescue
38
+ str
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module ShipHero
2
+ VERSION = "0.1.2".freeze
3
+ end
@@ -0,0 +1,34 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "ship_hero/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ship_hero"
8
+ spec.version = ShipHero::VERSION
9
+ spec.authors = ["Kyle Schutt"]
10
+ spec.email = ["kyle@revv.co"]
11
+
12
+ spec.summary = 'ShipHero API gives you the ability to integrate ShipHero with your custom e-commerce solution.'
13
+ spec.homepage = "https://github.com/revvco/ship_hero"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
+ f.match(%r{^(test|spec|features)/})
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_runtime_dependency("rest-client", '< 4.0', '>= 1.6.7')
27
+ spec.add_runtime_dependency("json", '~> 1.8', '>= 1.8.1')
28
+ spec.add_runtime_dependency('mime-types', '< 4.0', '>= 1.25.1')
29
+ spec.add_runtime_dependency('hashie', '< 4.0', '>= 1.2.0')
30
+
31
+ spec.add_development_dependency "bundler", "~> 1.16"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "rspec", "~> 3.0"
34
+ end
metadata ADDED
@@ -0,0 +1,211 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ship_hero
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Kyle Schutt
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-12-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "<"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.6.7
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "<"
28
+ - !ruby/object:Gem::Version
29
+ version: '4.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.6.7
33
+ - !ruby/object:Gem::Dependency
34
+ name: json
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.8'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 1.8.1
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.8'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 1.8.1
53
+ - !ruby/object:Gem::Dependency
54
+ name: mime-types
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "<"
58
+ - !ruby/object:Gem::Version
59
+ version: '4.0'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 1.25.1
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "<"
68
+ - !ruby/object:Gem::Version
69
+ version: '4.0'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 1.25.1
73
+ - !ruby/object:Gem::Dependency
74
+ name: hashie
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "<"
78
+ - !ruby/object:Gem::Version
79
+ version: '4.0'
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 1.2.0
83
+ type: :runtime
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "<"
88
+ - !ruby/object:Gem::Version
89
+ version: '4.0'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 1.2.0
93
+ - !ruby/object:Gem::Dependency
94
+ name: bundler
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '1.16'
100
+ type: :development
101
+ prerelease: false
102
+ version_requirements: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - "~>"
105
+ - !ruby/object:Gem::Version
106
+ version: '1.16'
107
+ - !ruby/object:Gem::Dependency
108
+ name: rake
109
+ requirement: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - "~>"
112
+ - !ruby/object:Gem::Version
113
+ version: '10.0'
114
+ type: :development
115
+ prerelease: false
116
+ version_requirements: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - "~>"
119
+ - !ruby/object:Gem::Version
120
+ version: '10.0'
121
+ - !ruby/object:Gem::Dependency
122
+ name: rspec
123
+ requirement: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - "~>"
126
+ - !ruby/object:Gem::Version
127
+ version: '3.0'
128
+ type: :development
129
+ prerelease: false
130
+ version_requirements: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - "~>"
133
+ - !ruby/object:Gem::Version
134
+ version: '3.0'
135
+ description:
136
+ email:
137
+ - kyle@revv.co
138
+ executables: []
139
+ extensions: []
140
+ extra_rdoc_files: []
141
+ files:
142
+ - ".gitignore"
143
+ - ".rspec"
144
+ - ".travis.yml"
145
+ - Gemfile
146
+ - Gemfile.lock
147
+ - LICENSE.txt
148
+ - README.md
149
+ - Rakefile
150
+ - bin/console
151
+ - bin/setup
152
+ - lib/ship_hero.rb
153
+ - lib/ship_hero/api.rb
154
+ - lib/ship_hero/exceptions/service_exception.rb
155
+ - lib/ship_hero/models/base.rb
156
+ - lib/ship_hero/models/image.rb
157
+ - lib/ship_hero/models/order.rb
158
+ - lib/ship_hero/models/order_history.rb
159
+ - lib/ship_hero/models/order_line_item.rb
160
+ - lib/ship_hero/models/order_line_item_product_shot.rb
161
+ - lib/ship_hero/models/order_note.rb
162
+ - lib/ship_hero/models/order_shipping_address.rb
163
+ - lib/ship_hero/models/order_shipping_lines.rb
164
+ - lib/ship_hero/models/product.rb
165
+ - lib/ship_hero/models/product_variant.rb
166
+ - lib/ship_hero/models/requests/get_order.rb
167
+ - lib/ship_hero/models/requests/get_orders.rb
168
+ - lib/ship_hero/models/requests/get_product.rb
169
+ - lib/ship_hero/models/requests/get_shipment.rb
170
+ - lib/ship_hero/models/responses/create_order.rb
171
+ - lib/ship_hero/models/responses/error.rb
172
+ - lib/ship_hero/models/responses/general.rb
173
+ - lib/ship_hero/models/responses/get_order.rb
174
+ - lib/ship_hero/models/responses/get_webhooks.rb
175
+ - lib/ship_hero/models/shipment.rb
176
+ - lib/ship_hero/models/webhook.rb
177
+ - lib/ship_hero/services/base_service.rb
178
+ - lib/ship_hero/services/order_service.rb
179
+ - lib/ship_hero/services/product_service.rb
180
+ - lib/ship_hero/services/shipment_service.rb
181
+ - lib/ship_hero/services/webhook_service.rb
182
+ - lib/ship_hero/util/config.rb
183
+ - lib/ship_hero/util/helpers.rb
184
+ - lib/ship_hero/version.rb
185
+ - ship_hero.gemspec
186
+ homepage: https://github.com/revvco/ship_hero
187
+ licenses:
188
+ - MIT
189
+ metadata: {}
190
+ post_install_message:
191
+ rdoc_options: []
192
+ require_paths:
193
+ - lib
194
+ required_ruby_version: !ruby/object:Gem::Requirement
195
+ requirements:
196
+ - - ">="
197
+ - !ruby/object:Gem::Version
198
+ version: '0'
199
+ required_rubygems_version: !ruby/object:Gem::Requirement
200
+ requirements:
201
+ - - ">="
202
+ - !ruby/object:Gem::Version
203
+ version: '0'
204
+ requirements: []
205
+ rubyforge_project:
206
+ rubygems_version: 2.7.6
207
+ signing_key:
208
+ specification_version: 4
209
+ summary: ShipHero API gives you the ability to integrate ShipHero with your custom
210
+ e-commerce solution.
211
+ test_files: []