fulfillment-api 1.1.7

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
+ SHA256:
3
+ metadata.gz: f86d3a067fe30dcd56e08e12bd05d4a12a926899fdb0f44f9a3542d2772e87a2
4
+ data.tar.gz: abb2fa42aec8a29bc6e0b7e741d5535d7cf76ea6074e011faed84f042795f894
5
+ SHA512:
6
+ metadata.gz: ff105f3acf96e2db4b003320e36d60136a7a600bb9fec90daf93e4d5c8e34a5f412ebfd004440ffd8b21ee60d83c85f3f5feaad2739bf99413289cd7393e9335
7
+ data.tar.gz: c40043a01da7e6f606e041c1bb7a6c7a99da5bd78ef57dedf2d94dfa975689d030c079bf6c7099f77cd7d20344b6dc5e4d6241932399b7baefc3e10359661353
@@ -0,0 +1,17 @@
1
+ version: 2.1
2
+
3
+ orbs:
4
+ gem: goldstar/publish-gem@1.0.1
5
+
6
+ workflows:
7
+ main:
8
+ jobs:
9
+ - gem/test
10
+ - gem/build-and-deploy:
11
+ context: packagecloud
12
+ requires:
13
+ - gem/test
14
+ filters:
15
+ branches:
16
+ only: master
17
+ packagecloud-repo: goldstar/production
@@ -0,0 +1,4 @@
1
+ /.bundle/
2
+ /tmp/
3
+ .ruby-version
4
+ vendor/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fulfillment-api.gemspec
4
+ gemspec
5
+
6
+ source 'https://adfbf0d33119222cf515a5a523d643c44c386be29fa1f0c1:@packagecloud.io/goldstar/production' do
7
+ gem 'outbox', '1.0.0'
8
+ end
@@ -0,0 +1,87 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fulfillment-api (1.1.7)
5
+ activesupport (< 5.3)
6
+ faraday (< 0.15)
7
+ faraday_middleware (< 0.13)
8
+ hashie (< 3.7)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ remote: https://adfbf0d33119222cf515a5a523d643c44c386be29fa1f0c1:@packagecloud.io/goldstar/production/
13
+ specs:
14
+ activesupport (5.2.4.1)
15
+ concurrent-ruby (~> 1.0, >= 1.0.2)
16
+ i18n (>= 0.7, < 2)
17
+ minitest (~> 5.1)
18
+ tzinfo (~> 1.1)
19
+ addressable (2.6.0)
20
+ public_suffix (>= 2.0.2, < 4.0)
21
+ byebug (11.0.1)
22
+ concurrent-ruby (1.1.5)
23
+ crack (0.4.3)
24
+ safe_yaml (~> 1.0.0)
25
+ diff-lcs (1.3)
26
+ faraday (0.14.0)
27
+ multipart-post (>= 1.2, < 3)
28
+ faraday_middleware (0.12.2)
29
+ faraday (>= 0.7.4, < 1.0)
30
+ hashdiff (1.0.0)
31
+ hashie (3.6.0)
32
+ i18n (1.7.0)
33
+ concurrent-ruby (~> 1.0)
34
+ minitest (5.13.0)
35
+ multipart-post (2.1.1)
36
+ outbox (1.0.0)
37
+ activesupport (< 5.3)
38
+ hashie (< 3.7)
39
+ xmlrpc (~> 0.3)
40
+ public_suffix (3.1.1)
41
+ rake (10.5.0)
42
+ rspec (3.8.0)
43
+ rspec-core (~> 3.8.0)
44
+ rspec-expectations (~> 3.8.0)
45
+ rspec-mocks (~> 3.8.0)
46
+ rspec-core (3.8.2)
47
+ rspec-support (~> 3.8.0)
48
+ rspec-expectations (3.8.4)
49
+ diff-lcs (>= 1.2.0, < 2.0)
50
+ rspec-support (~> 3.8.0)
51
+ rspec-its (1.3.0)
52
+ rspec-core (>= 3.0.0)
53
+ rspec-expectations (>= 3.0.0)
54
+ rspec-mocks (3.8.1)
55
+ diff-lcs (>= 1.2.0, < 2.0)
56
+ rspec-support (~> 3.8.0)
57
+ rspec-support (3.8.2)
58
+ rspec_junit_formatter (0.4.1)
59
+ rspec-core (>= 2, < 4, != 2.12.0)
60
+ safe_yaml (1.0.5)
61
+ thread_safe (0.3.6)
62
+ tzinfo (1.2.5)
63
+ thread_safe (~> 0.1)
64
+ vcr (3.0.3)
65
+ webmock (2.3.2)
66
+ addressable (>= 2.3.6)
67
+ crack (>= 0.3.2)
68
+ hashdiff
69
+ xmlrpc (0.3.0)
70
+
71
+ PLATFORMS
72
+ ruby
73
+
74
+ DEPENDENCIES
75
+ bundler
76
+ byebug
77
+ fulfillment-api!
78
+ outbox (= 1.0.0)!
79
+ rake (~> 10.0)
80
+ rspec (~> 3.0)
81
+ rspec-its (~> 1.2)
82
+ rspec_junit_formatter
83
+ vcr (~> 3.0)
84
+ webmock (~> 2.1)
85
+
86
+ BUNDLED WITH
87
+ 1.17.3
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Matt White
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,25 @@
1
+ # Fulfillment::Api
2
+
3
+ API wrapper for interacting with the Goldstar Fulfillment app.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'fulfillment-api', git: 'git@github.com:goldstar/fulfillment-api.git'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ ## Usage
18
+
19
+ TODO: Write usage instructions here
20
+
21
+ ## Development
22
+
23
+ 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.
24
+
25
+ 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).
@@ -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 "fulfillment"
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
@@ -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,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fulfillment/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'fulfillment-api'
8
+ spec.version = Fulfillment::Api::VERSION
9
+ spec.authors = ['Matt White']
10
+ spec.email = ['mwhite@goldstar.com']
11
+
12
+ spec.summary = %q{API wrapper for interacting with the Goldstar Fulfillment app.}
13
+ spec.homepage = 'https://github.com/goldstar/fulfillment-api'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(spec)/})
18
+ end
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'byebug'
22
+ spec.add_development_dependency 'bundler'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rspec', '~> 3.0'
25
+ spec.add_development_dependency 'rspec-its', '~> 1.2'
26
+ spec.add_development_dependency 'webmock', '~> 2.1'
27
+ spec.add_development_dependency 'vcr', '~> 3.0'
28
+ spec.add_development_dependency 'rspec_junit_formatter'
29
+
30
+ spec.add_runtime_dependency 'activesupport', '< 5.3'
31
+ spec.add_runtime_dependency 'faraday', '< 0.15'
32
+ spec.add_runtime_dependency 'faraday_middleware', '< 0.13'
33
+ spec.add_runtime_dependency 'hashie', '< 3.7'
34
+ end
@@ -0,0 +1,45 @@
1
+ require "active_support/configurable"
2
+ require "active_support/core_ext/array/wrap"
3
+ require "outbox"
4
+
5
+ require "fulfillment/errors"
6
+ require "fulfillment/version"
7
+
8
+ module Fulfillment
9
+ include ActiveSupport::Configurable
10
+
11
+ config_accessor :proxy
12
+
13
+ autoload :Api, "fulfillment/api"
14
+ autoload :Client, "fulfillment/client"
15
+ autoload :Model, "fulfillment/model"
16
+ autoload :Request, "fulfillment/request"
17
+ autoload :Response, "fulfillment/response"
18
+ autoload :Resource, "fulfillment/resource"
19
+
20
+ module Models
21
+ autoload :Collection, "fulfillment/models/collection"
22
+ autoload :Deliverable, "fulfillment/models/deliverable"
23
+ autoload :Order, "fulfillment/models/order"
24
+ autoload :Product, "fulfillment/models/product"
25
+ autoload :Voucher, "fulfillment/models/voucher"
26
+ end
27
+
28
+ module Requests
29
+ end
30
+
31
+ module Resources
32
+ autoload :Inventories, "fulfillment/resources/inventories"
33
+ autoload :Orders, "fulfillment/resources/orders"
34
+ autoload :Organizations, "fulfillment/resources/organizations"
35
+ autoload :Manifests, "fulfillment/resources/manifests"
36
+ autoload :Products, "fulfillment/resources/products"
37
+ autoload :Types, "fulfillment/resources/types"
38
+ autoload :Venues, "fulfillment/resources/venues"
39
+ autoload :Vouchers, "fulfillment/resources/vouchers"
40
+ end
41
+
42
+ def self.client
43
+ @client ||= Client.new
44
+ end
45
+ end
@@ -0,0 +1,33 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+
4
+ module Fulfillment
5
+ class Client
6
+ def connection
7
+ @connection ||= Faraday.new(proxy: config.proxy) do |conn|
8
+ conn.request :json
9
+ conn.response :json
10
+ conn.adapter Faraday.default_adapter
11
+ end
12
+ end
13
+
14
+ def call(method, path, params={})
15
+ raw_response = connection.public_send(method, path, params) do |req|
16
+ req.options.timeout = params[:query]&.delete(:request_timeout) || 30
17
+ end
18
+ Response.new(raw_response)
19
+ end
20
+
21
+ [:get, :post, :put, :patch, :delete].each do |method|
22
+ define_method(method) do |path, params={}|
23
+ call(method, path, params)
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def config
30
+ Fulfillment.config
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,35 @@
1
+ module Fulfillment
2
+ Error = Class.new(StandardError)
3
+
4
+ # HTTP errors
5
+ HttpError = Class.new(Error)
6
+ ServerError = Class.new(HttpError)
7
+
8
+ # Service errors
9
+ class ServiceError < Error
10
+ attr_reader :error
11
+
12
+ def initialize(response_body = {})
13
+ @error = response_body.fetch("error", {}) if response_body
14
+ end
15
+
16
+ def message
17
+ error&.dig("message")
18
+ end
19
+ alias_method :to_s, :message
20
+
21
+ def status
22
+ error&.dig("status")
23
+ end
24
+
25
+ def type
26
+ error&.dig("type")
27
+ end
28
+ end
29
+
30
+ InvalidRequest = Class.new(ServiceError)
31
+ InvalidEvent = Class.new(ServiceError)
32
+ AccessDenied = Class.new(ServiceError)
33
+ ResourceNotFound = Class.new(ServiceError)
34
+ MethodNotAllowed = Class.new(ServiceError)
35
+ end
@@ -0,0 +1,10 @@
1
+ require "hashie"
2
+
3
+ module Fulfillment
4
+ class Model < Hashie::Trash
5
+ include Hashie::Extensions::Dash::Coercion
6
+ include Hashie::Extensions::IgnoreUndeclared
7
+ include Hashie::Extensions::IndifferentAccess
8
+ include Hashie::Extensions::MethodAccess
9
+ end
10
+ end
@@ -0,0 +1,23 @@
1
+ module Fulfillment
2
+ module Models
3
+ class Collection
4
+ include Enumerable
5
+ extend Forwardable
6
+
7
+ attr_reader :items, :_items
8
+
9
+ delegate [:[], :each, :last, :size] => :items
10
+
11
+ def initialize(item_type, items)
12
+ @_items = items
13
+ @items = Array.wrap(_items).map do |item|
14
+ item_type.new(item)
15
+ end
16
+ end
17
+
18
+ def [](value)
19
+ items.force[value]
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,13 @@
1
+ module Fulfillment
2
+ module Models
3
+ class Deliverable < Model
4
+ property :id, coerce: Integer
5
+ property :creator_type
6
+ property :code
7
+ property :image_url
8
+ property :claimed_at, coerce: ->(v) { DateTime.parse(v) rescue v }
9
+ property :provider
10
+ property :product_id, coerce: Integer
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,39 @@
1
+ module Fulfillment
2
+ module Models
3
+ class Order < Model
4
+ autoload :Voucher, "fulfillment/models/voucher"
5
+
6
+ property :id, coerce: Integer
7
+ property :email
8
+ property :first_name
9
+ property :last_name
10
+ property :purchase_id, coerce: Integer
11
+ property :ticket_filename
12
+ property :voucher_filename
13
+ property :voucher_url
14
+ property :confirmation_number
15
+ property :user_id, coerce: Integer
16
+ property :procurement_data, coerce: Hash, default: {}
17
+ property :fulfillment_data, coerce: Hash, default: {}
18
+ property :status
19
+ property :note
20
+ property :estimated_commission
21
+ property :flagged
22
+ property :marketing_opt_in
23
+ property :partner
24
+ property :releasable?
25
+ property :vouchers, coerce: Array[Models::Voucher], default: []
26
+
27
+ def error_message
28
+ procurement_data['error_message']
29
+ end
30
+
31
+ def status
32
+ return 'Failed' if !error_message.nil?
33
+ return 'Flagged' if flagged?
34
+ return 'Pending' if self[:status].nil?
35
+ self[:status]
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,25 @@
1
+ module Fulfillment
2
+ module Models
3
+ class Product < Model
4
+ property :id, coerce: Integer
5
+ property :venue
6
+ property :event_title
7
+ property :show_id, coerce: Integer
8
+ property :supplier_manifest_emails, coerce: ->(v) { v.split("\n") rescue v }
9
+ property :supplier_id, coerce: Integer
10
+ property :fulfillment_details
11
+ property :advisories
12
+ property :created_at, coerce: ->(v) { DateTime.parse(v) rescue v }
13
+ property :updated_at, coerce: ->(v) { DateTime.parse(v) rescue v }
14
+ property :show_date_and_time
15
+ property :automatically_generate_barcode
16
+ property :inventory_id, coerce: Integer
17
+ property :fulfillment_method
18
+ property :fulfillment_data
19
+ property :event_id, coerce: Integer
20
+ property :allow_purchase_cancellations
21
+ property :supplier_wrap_sheet_emails, coerce: ->(v) { v.split("\n") rescue v }
22
+ property :barcode_format
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,31 @@
1
+ module Fulfillment
2
+ module Models
3
+ class Voucher < Model
4
+ autoload :Deliverable, "fulfillment/models/deliverable"
5
+
6
+ property :id, coerce: Integer
7
+ property :order_id, coerce: Integer
8
+ property :first_name
9
+ property :last_name
10
+ property :offer_name
11
+ property :deliverable_id, coerce: Integer
12
+ property :user_id, coerce: Integer
13
+ property :redeemed
14
+ property :redeemed_at
15
+ property :code
16
+ property :purchase_id, coerce: Integer
17
+ property :procurement_data, coerce: Hash, default: {}
18
+ property :fulfillment_data, coerce: Hash, default: {}
19
+ property :deliverable, coerce: Models::Deliverable
20
+
21
+ def code
22
+ self[:code] || deliverable&.code
23
+ end
24
+
25
+ def redeemed
26
+ !redeemed_at.nil? && !redeemed_at.empty?
27
+ end
28
+ alias_method :redeemed?, :redeemed
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,44 @@
1
+ require "uri"
2
+
3
+ module Fulfillment
4
+ class Request
5
+ attr_reader :path, :params
6
+
7
+ def initialize(path, params={})
8
+ @path = path
9
+ @params = params
10
+ end
11
+
12
+ def call(method)
13
+ response = client.public_send(method, uri, params)
14
+ response.on_error(&:raise_errors)
15
+ end
16
+
17
+ [:get, :post, :put, :patch, :delete].each do |method|
18
+ define_method(method) do
19
+ call(method)
20
+ end
21
+ end
22
+
23
+ def uri
24
+ @uri ||= build_uri
25
+ end
26
+
27
+ private
28
+
29
+ def build_uri
30
+ URI.parse(endpoint).tap do |uri|
31
+ uri.merge!(path)
32
+ end
33
+ end
34
+
35
+ def endpoint
36
+ return Fulfillment.config.endpoint if Fulfillment.config.endpoint =~ /^http/
37
+ "http://#{Fulfillment.config.endpoint}"
38
+ end
39
+
40
+ def client
41
+ Fulfillment.client
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,43 @@
1
+ module Fulfillment
2
+ module Resources
3
+ module Inventories
4
+ FIND_ALL_RESPONSE_MODELS = {
5
+ "outbox" => ::Outbox::Models::Event
6
+ }
7
+ FIND_ALL_RESPONSE_MODELS.default = OpenStruct
8
+ FIND_RESPONSE_MODELS = {
9
+ "outbox" => ::Outbox::Models::PriceLevelSeat
10
+ }
11
+ FIND_RESPONSE_MODELS.default = OpenStruct
12
+
13
+ extend self
14
+
15
+ def find_all(fulfillment_method:, wrap: true, **params)
16
+ response = Request.new("inventories", id: fulfillment_method, query: params).get
17
+ if wrap
18
+ Models::Collection.new(FIND_ALL_RESPONSE_MODELS[fulfillment_method], response.body)
19
+ else
20
+ response.body
21
+ end
22
+ end
23
+
24
+ # We don't use a resource ID here but rather the fulfillment method as the ID
25
+ # because different fulfillment methods use different ways of finding resources
26
+ # other than just a plain ID. Any applicable resource ID should be passed to the params.
27
+ def find(fulfillment_method:, wrap: true, **params)
28
+ response = Request.new("inventories/#{fulfillment_method}", query: params).get
29
+ return if response.body.nil? || response.body.empty?
30
+ if wrap
31
+ Models::Collection.new(FIND_RESPONSE_MODELS[fulfillment_method], response.body)
32
+ else
33
+ response.body
34
+ end
35
+ end
36
+
37
+ def update(fulfillment_method:, **params)
38
+ response = Request.new("inventories/#{fulfillment_method}", query: params).put
39
+ response.success?
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,12 @@
1
+ module Fulfillment
2
+ module Resources
3
+ module Manifests
4
+ extend self
5
+
6
+ def create(params={})
7
+ response = Request.new("manifests", params).post
8
+ response.body
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,23 @@
1
+ module Fulfillment
2
+ module Resources
3
+ module Orders
4
+ extend self
5
+
6
+ def find(params={})
7
+ response = Request.new("orders/search", { search: params }).post
8
+ Models::Collection.new(Models::Order, response.body)
9
+ end
10
+
11
+ def update(params={})
12
+ id = params.delete(:id)
13
+ response = Request.new("orders/#{id}", params).patch
14
+ Models::Order.new(response.body)
15
+ end
16
+
17
+ def destroy(id)
18
+ response = Request.new("orders/#{id}").delete
19
+ response.status == 200
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,26 @@
1
+ module Fulfillment
2
+ module Resources
3
+ module Organizations
4
+ extend self
5
+
6
+ def find_all
7
+ response = Request.new("organizations").get
8
+ response.body
9
+ end
10
+
11
+ def find(organization_id, type_name = nil)
12
+ request = ["organizations", organization_id, type_name].compact.join("/")
13
+ response = Request.new(request).get
14
+ response.body
15
+ end
16
+
17
+ def update(organization_id, type_name, data)
18
+ response = Request.new(
19
+ "organizations/#{organization_id}/#{type_name}",
20
+ {data: data}
21
+ ).post
22
+ response.body
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,20 @@
1
+ module Fulfillment
2
+ module Resources
3
+ module Products
4
+ extend self
5
+
6
+ def find(params={})
7
+ response = Request.new("products", { search: params }).get
8
+ Models::Collection.new(Models::Product, response.body)
9
+ end
10
+
11
+ def create_or_update(params={})
12
+ response = Request.new("products", params).post
13
+ end
14
+
15
+ def update_all(show_id:, params:)
16
+ response = Request.new("products/#{show_id}", params).patch
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ module Fulfillment
2
+ module Resources
3
+ module Types
4
+ extend self
5
+
6
+ def find_all
7
+ response = Request.new("types").get
8
+ response.body
9
+ end
10
+
11
+ def find(type_name)
12
+ response = Request.new("types/#{type_name}").get
13
+ response.body
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ module Fulfillment
2
+ module Resources
3
+ module Venues
4
+ extend self
5
+
6
+ def search(fulfillment_method, params)
7
+ response = Request.new("venues", fulfillment_method: fulfillment_method, query: params).get
8
+ response.body
9
+ end
10
+
11
+ def find(fulfillment_method, id)
12
+ response = Request.new("venues/#{id}", fulfillment_method: fulfillment_method).get
13
+ return if response.body.nil? || response.body.empty?
14
+ response.body
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ module Fulfillment
2
+ module Resources
3
+ module Vouchers
4
+ extend self
5
+
6
+ def find_all(params={})
7
+ response = Request.new("vouchers", { search: params }).get
8
+ Models::Collection.new(Models::Voucher, response.body)
9
+ end
10
+
11
+ def update(params={})
12
+ response = Request.new("vouchers/#{params[:id]}", params).patch
13
+ Models::Voucher.new(response.body)
14
+ end
15
+
16
+ def redeem(params={})
17
+ response = Request.new("vouchers/#{params[:show_id]}/#{params[:code]}/redeem", params).patch
18
+ Models::Voucher.new(response.body)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,41 @@
1
+ module Fulfillment
2
+ class Response
3
+ extend Forwardable
4
+
5
+ attr_reader :raw_response, :errors
6
+
7
+ delegate [:body, :status] => :raw_response
8
+
9
+ def initialize(raw_response)
10
+ @raw_response = raw_response
11
+ end
12
+
13
+ def success?
14
+ (200..299).include?(status)
15
+ end
16
+
17
+ def on_error
18
+ yield self unless success?
19
+ self
20
+ end
21
+
22
+ def raise_errors
23
+ case status
24
+ when 400
25
+ fail InvalidRequest, body
26
+ when 401
27
+ fail AccessDenied, body
28
+ when 403
29
+ fail InvalidEvent, body
30
+ when 404
31
+ fail ResourceNotFound, body
32
+ when 405
33
+ fail MethodNotAllowed, body
34
+ when (400..499)
35
+ fail ServiceError, body
36
+ when (500..599)
37
+ fail ServerError, body
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,5 @@
1
+ module Fulfillment
2
+ module Api
3
+ VERSION = "1.1.7"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,243 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fulfillment-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.7
5
+ platform: ruby
6
+ authors:
7
+ - Matt White
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-08-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: byebug
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-its
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.1'
97
+ - !ruby/object:Gem::Dependency
98
+ name: vcr
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec_junit_formatter
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: activesupport
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "<"
130
+ - !ruby/object:Gem::Version
131
+ version: '5.3'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "<"
137
+ - !ruby/object:Gem::Version
138
+ version: '5.3'
139
+ - !ruby/object:Gem::Dependency
140
+ name: faraday
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "<"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.15'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "<"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.15'
153
+ - !ruby/object:Gem::Dependency
154
+ name: faraday_middleware
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "<"
158
+ - !ruby/object:Gem::Version
159
+ version: '0.13'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "<"
165
+ - !ruby/object:Gem::Version
166
+ version: '0.13'
167
+ - !ruby/object:Gem::Dependency
168
+ name: hashie
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "<"
172
+ - !ruby/object:Gem::Version
173
+ version: '3.7'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "<"
179
+ - !ruby/object:Gem::Version
180
+ version: '3.7'
181
+ description:
182
+ email:
183
+ - mwhite@goldstar.com
184
+ executables: []
185
+ extensions: []
186
+ extra_rdoc_files: []
187
+ files:
188
+ - ".circleci/config.yml"
189
+ - ".gitignore"
190
+ - ".rspec"
191
+ - Gemfile
192
+ - Gemfile.lock
193
+ - LICENSE.txt
194
+ - README.md
195
+ - Rakefile
196
+ - bin/console
197
+ - bin/setup
198
+ - fulfillment-api.gemspec
199
+ - lib/fulfillment.rb
200
+ - lib/fulfillment/client.rb
201
+ - lib/fulfillment/errors.rb
202
+ - lib/fulfillment/model.rb
203
+ - lib/fulfillment/models/collection.rb
204
+ - lib/fulfillment/models/deliverable.rb
205
+ - lib/fulfillment/models/order.rb
206
+ - lib/fulfillment/models/product.rb
207
+ - lib/fulfillment/models/voucher.rb
208
+ - lib/fulfillment/request.rb
209
+ - lib/fulfillment/resources/inventories.rb
210
+ - lib/fulfillment/resources/manifests.rb
211
+ - lib/fulfillment/resources/orders.rb
212
+ - lib/fulfillment/resources/organizations.rb
213
+ - lib/fulfillment/resources/products.rb
214
+ - lib/fulfillment/resources/types.rb
215
+ - lib/fulfillment/resources/venues.rb
216
+ - lib/fulfillment/resources/vouchers.rb
217
+ - lib/fulfillment/response.rb
218
+ - lib/fulfillment/version.rb
219
+ homepage: https://github.com/goldstar/fulfillment-api
220
+ licenses:
221
+ - MIT
222
+ metadata: {}
223
+ post_install_message:
224
+ rdoc_options: []
225
+ require_paths:
226
+ - lib
227
+ required_ruby_version: !ruby/object:Gem::Requirement
228
+ requirements:
229
+ - - ">="
230
+ - !ruby/object:Gem::Version
231
+ version: '0'
232
+ required_rubygems_version: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
237
+ requirements: []
238
+ rubyforge_project:
239
+ rubygems_version: 2.7.6.2
240
+ signing_key:
241
+ specification_version: 4
242
+ summary: API wrapper for interacting with the Goldstar Fulfillment app.
243
+ test_files: []