extend_warranties 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f4154f93a054e0403ed71f808216b3a7e2c8d7ed34174fdc60dadaf05d912c96
4
+ data.tar.gz: 99eb05158a27e51e97bb38a2536e9e122d07978b5db3f3149b9855aabc831f42
5
+ SHA512:
6
+ metadata.gz: 1a737fe2376345bb62ef25213b08aba9bf2676913ebbccabc4710a911ec0922da985acb0ed38e198066aaf64529f34fd8996ede92895e153cc098b54ed58728c
7
+ data.tar.gz: 22078797be4c21d2e578445bc52125547e5d8ceae0c87b2affaf75a2cc70211c4b5845d4f48347e9ecc246776b11dce4f23912a329b11bf5376a27fe918aed12
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /Gemfile.lock
10
+ /spec/env.yml
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.0
7
+ before_install: gem install bundler -v 1.17.3
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 extend_warranties.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Allison Reilly
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
+ # ExtendWarranties
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/extend_warranties`. 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 'extend_warranties'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install extend_warranties
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]/extend_warranties.
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 "extend_warranties"
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,36 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "extend_warranties/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "extend_warranties"
8
+ spec.version = ExtendWarranties::VERSION
9
+ spec.authors = ["Allison Reilly", "Daniel J. Pritchett"]
10
+ spec.email = ["acreilly3@gmail.com", "dpritchett@gmail.com"]
11
+
12
+ spec.summary = %q{Ruby client for Extend API}
13
+ spec.description = %q{Ruby client for Extend API}
14
+ # spec.homepage = "TODO: Put your gem's website or public repo URL here."
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| 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 "activesupport"
27
+ spec.add_runtime_dependency "faraday"
28
+ spec.add_runtime_dependency "faraday_middleware"
29
+
30
+ spec.add_development_dependency "bundler", ">= 1.17"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec", "~> 3.0"
33
+ spec.add_development_dependency "rspec-its"
34
+ spec.add_development_dependency "vcr"
35
+ spec.add_development_dependency "webmock"
36
+ end
@@ -0,0 +1,15 @@
1
+ require 'active_support/all'
2
+ require 'faraday'
3
+ require 'faraday_middleware'
4
+
5
+ require 'extend_warranties/version'
6
+ require 'extend_warranties/response'
7
+
8
+ require 'extend_warranties/api/base'
9
+ require 'extend_warranties/api/products'
10
+ require 'extend_warranties/api/plans'
11
+ require 'extend_warranties/api/contracts'
12
+ require 'extend_warranties/api/offers'
13
+
14
+ require 'extend_warranties/configuration'
15
+ require 'extend_warranties/client'
@@ -0,0 +1,18 @@
1
+ module ExtendWarranties
2
+ module Api
3
+ class Base
4
+ attr_reader :connection
5
+
6
+ def initialize(connection)
7
+ @connection = connection
8
+ end
9
+
10
+ protected
11
+
12
+ def handle_response(response)
13
+ # Wrap in our own response class
14
+ ExtendWarranties::Response.new response
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,29 @@
1
+ module ExtendWarranties
2
+ module Api
3
+ class Contracts < Base
4
+
5
+ def create(store_id, args = {})
6
+ raise ArgumentError, 'store_id is required' if store_id.blank?
7
+
8
+ resp = connection.post "/stores/#{store_id}/contracts", args
9
+ handle_response(resp)
10
+ end
11
+
12
+ def refund(store_id, contract_id, args = {})
13
+ raise ArgumentError, 'store_id is required' if store_id.blank?
14
+ raise ArgumentError, 'contract_id is required' if contract_id.blank?
15
+
16
+ resp = connection.post "/stores/#{store_id}/contracts/#{contract_id}/refund", args
17
+ handle_response(resp)
18
+ end
19
+
20
+ def get_invoice(store_id, contract_id, args = {})
21
+ raise ArgumentError, 'store_id is required' if store_id.blank?
22
+ raise ArgumentError, 'contract_id is required' if contract_id.blank?
23
+
24
+ resp = connection.get "/stores/#{store_id}/contracts/#{contract_id}/invoice", args
25
+ handle_response(resp)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,14 @@
1
+ module ExtendWarranties
2
+ module Api
3
+ class Offers < Base
4
+
5
+ def find_by_id(store_id, product_id, args = {})
6
+ raise ArgumentError, 'store_id is required' if store_id.blank?
7
+ raise ArgumentError, 'product_id is required' if product_id.blank?
8
+
9
+ resp = connection.get "/offers?storeId=#{store_id}&productId=#{product_id}", args
10
+ handle_response(resp)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ module ExtendWarranties
2
+ module Api
3
+ class Plans < Base
4
+
5
+ def all(store_id, args = {})
6
+ resp = connection.get "/offers/list?storeId=#{store_id}", args
7
+
8
+ handle_response(resp)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,43 @@
1
+ module ExtendWarranties
2
+ module Api
3
+ class Products < Base
4
+
5
+ def all(store_id, args = {})
6
+ raise ArgumentError, 'store_id is required' if store_id.blank?
7
+
8
+ resp = connection.get "/stores/#{store_id}/products", args
9
+ handle_response(resp)
10
+ end
11
+
12
+ def create(store_id, args = {})
13
+ raise ArgumentError, 'store_id is required' if store_id.blank?
14
+
15
+ resp = connection.post "/stores/#{store_id}/products", args
16
+ handle_response(resp)
17
+ end
18
+
19
+ def update(store_id, product_id, args = {})
20
+ raise ArgumentError, 'store_id is required' if store_id.blank?
21
+
22
+ resp = connection.put "/stores/#{store_id}/products/#{product_id}", args
23
+ handle_response(resp)
24
+ end
25
+
26
+ def find_by_id(store_id, product_id, args = {})
27
+ raise ArgumentError, 'store_id is required' if store_id.blank?
28
+ raise ArgumentError, 'product_id is required' if product_id.blank?
29
+
30
+ resp = connection.get "/stores/#{store_id}/products/#{product_id}", args
31
+ handle_response(resp)
32
+ end
33
+
34
+ def delete(store_id, product_id, args={})
35
+ raise ArgumentError, 'store_id is required' if store_id.blank?
36
+ raise ArgumentError, 'product_id is required' if product_id.blank?
37
+
38
+ resp = connection.delete "/stores/#{store_id}/products/#{product_id}", args
39
+ handle_response(resp)
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,50 @@
1
+ module ExtendWarranties
2
+ class Client
3
+ @namespaces = []
4
+ @connection = nil
5
+
6
+ ##
7
+ # Defines a method to access class instance.
8
+ #
9
+ def self.namespace(name)
10
+ converted = name.to_s.split('_').map(&:capitalize).join
11
+ klass = ExtendWarranties::Api.const_get(converted)
12
+ @namespaces << klass
13
+ end
14
+
15
+ namespace :products
16
+
17
+ namespace :plans
18
+
19
+ namespace :contracts
20
+
21
+ namespace :offers
22
+
23
+
24
+ def initialize(args = {})
25
+ @configuration = ExtendWarranties::Configuration.new(args)
26
+
27
+ @connection = Faraday.new(url: @configuration.base_url) do |conn|
28
+ conn.request :json
29
+ conn.headers = @configuration.headers
30
+
31
+ conn.response :json
32
+ conn.response :logger
33
+
34
+ conn.adapter Faraday.default_adapter
35
+ end
36
+
37
+ create_instances
38
+ end
39
+
40
+ private
41
+
42
+ def create_instances
43
+ namespaces = self.class.instance_variable_get(:@namespaces)
44
+ namespaces.each do |klass|
45
+ reader = klass.to_s.split('::').last.underscore
46
+ self.class.send(:define_method, reader.to_sym) { klass.new @connection }
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,35 @@
1
+ module ExtendWarranties
2
+ class Configuration
3
+ attr_reader :sandbox, :base_url, :env, :access_token, :store_id, :headers
4
+
5
+ REST_URLS = {
6
+ sandbox: 'https://api-demo.helloextend.com',
7
+ production: 'https://api.helloextend.com'
8
+ }
9
+
10
+ SANDBOX = :sandbox
11
+ PRODUCTION = :production
12
+
13
+ def initialize(args = {})
14
+ validate_args(args)
15
+
16
+ @env = args[:env].to_sym
17
+ @sandbox = @env == SANDBOX
18
+ @base_url = REST_URLS[env]
19
+ @access_token = args[:access_token]
20
+ @headers = args[:headers] || { 'Content-Type' => 'application/json', 'X-Extend-Access-Token' => @access_token }
21
+ @store_id = args[:store_id]
22
+ end
23
+
24
+ private
25
+
26
+ def validate_args(args)
27
+ raise ArgumentError, 'access token is required' if args[:access_token].blank?
28
+ raise ArgumentError, 'store id is required' if args[:store_id].blank?
29
+ raise ArgumentError, 'env is required' if args[:env].blank?
30
+
31
+ return if [SANDBOX, PRODUCTION].include?(args[:env].to_sym)
32
+ raise ArgumentError, 'env must be of :sandbox or :production'
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,8 @@
1
+ module ExtendWarranties
2
+ class Response < Faraday::Response
3
+ def initialize(response)
4
+ super()
5
+ finish(response.env)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module ExtendWarranties
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,191 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: extend_warranties
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Allison Reilly
8
+ - Daniel J. Pritchett
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2020-04-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: faraday
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: faraday_middleware
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: bundler
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '1.17'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '1.17'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rake
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '10.0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '10.0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rspec
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '3.0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '3.0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: rspec-its
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: vcr
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: webmock
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ description: Ruby client for Extend API
141
+ email:
142
+ - acreilly3@gmail.com
143
+ - dpritchett@gmail.com
144
+ executables: []
145
+ extensions: []
146
+ extra_rdoc_files: []
147
+ files:
148
+ - ".gitignore"
149
+ - ".rspec"
150
+ - ".travis.yml"
151
+ - Gemfile
152
+ - LICENSE.txt
153
+ - README.md
154
+ - Rakefile
155
+ - bin/console
156
+ - bin/setup
157
+ - extend_warranties.gemspec
158
+ - lib/extend_warranties.rb
159
+ - lib/extend_warranties/api/base.rb
160
+ - lib/extend_warranties/api/contracts.rb
161
+ - lib/extend_warranties/api/offers.rb
162
+ - lib/extend_warranties/api/plans.rb
163
+ - lib/extend_warranties/api/products.rb
164
+ - lib/extend_warranties/client.rb
165
+ - lib/extend_warranties/configuration.rb
166
+ - lib/extend_warranties/response.rb
167
+ - lib/extend_warranties/version.rb
168
+ homepage:
169
+ licenses:
170
+ - MIT
171
+ metadata: {}
172
+ post_install_message:
173
+ rdoc_options: []
174
+ require_paths:
175
+ - lib
176
+ required_ruby_version: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ required_rubygems_version: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - ">="
184
+ - !ruby/object:Gem::Version
185
+ version: '0'
186
+ requirements: []
187
+ rubygems_version: 3.1.2
188
+ signing_key:
189
+ specification_version: 4
190
+ summary: Ruby client for Extend API
191
+ test_files: []