oreilly_api 1.0.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '09364ca17a234cc27c6829b0317dadc2c81cec676ab74986fdf6f13198f7cf0f'
4
+ data.tar.gz: e2fe98659b11d63da56f5757bf92eddf0b54941eb5b1a6f01a95c790089d9632
5
+ SHA512:
6
+ metadata.gz: 65f0837929cf1333b20af74f1af02d7da2faacca75dcfa7cfda7faa6dbb148de678db5839c3ed0f136a77b6622c4c2925613fd246f59191b1626a8e5ee97edad
7
+ data.tar.gz: 82c5dcd33f177b7c1ada7c66dbdfadd913eff3a80f5fceb392b5b5ab793c64081b20239927caabdfa4adeabef52da8923c1ecee4611cf6f2b9269c842bd49994
@@ -0,0 +1,54 @@
1
+ version: 2
2
+ jobs:
3
+ build:
4
+ working_directory: ~/YourMechanic/oreilly_api
5
+ parallelism: 1
6
+ shell: /bin/bash --login
7
+
8
+ environment:
9
+ CIRCLE_ARTIFACTS: /tmp/circleci-artifacts
10
+ CIRCLE_TEST_REPORTS: /tmp/circleci-test-results
11
+ docker:
12
+ - image: circleci/ruby:2.6.2
13
+ steps:
14
+ - checkout
15
+ - run: mkdir -p $CIRCLE_ARTIFACTS $CIRCLE_TEST_REPORTS
16
+ - restore_cache:
17
+ keys:
18
+ # This branch if available
19
+ - v2-dep-{{ .Branch }}-
20
+ # Default branch if not
21
+ - v2-dep-master-
22
+ # Any branch if there are none on the default branch - this should be unnecessary if you have your default branch configured correctly
23
+ - v2-dep-
24
+ - run:
25
+ name: Install bundler for oreilly_api
26
+ working_directory: ~/YourMechanic/oreilly_api
27
+ command: gem install bundler:2.2.8
28
+ - run:
29
+ name: Install Gems for oreilly_api
30
+ working_directory: ~/YourMechanic/oreilly_api
31
+ command: bundle install
32
+ # Save dependency cache
33
+ - save_cache:
34
+ key: v2-dep-{{ .Branch }}-{{ epoch }}
35
+ paths:
36
+ - vendor/bundle
37
+ - ~/virtualenvs
38
+ - ~/.m2
39
+ - ~/.ivy2
40
+ - ~/.bundle
41
+ - run:
42
+ working_directory: ~/YourMechanic/oreilly_api
43
+ command: bundle exec rubocop
44
+ - run:
45
+ working_directory: ~/YourMechanic/oreilly_api
46
+ command: bundle exec rspec --colour --drb --profile -fd --format progress $(circleci tests glob "spec/*_spec.rb" | circleci tests split)
47
+ - store_test_results:
48
+ path: /tmp/circleci-test-results
49
+ - store_artifacts:
50
+ path: /tmp/circleci-artifacts
51
+ - store_artifacts:
52
+ path: /tmp/circleci-test-results
53
+ - store_artifacts:
54
+ path: oreilly_api/coverage
data/.gitignore ADDED
@@ -0,0 +1,56 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ # Ignore Byebug command history file.
17
+ .byebug_history
18
+
19
+ ## Specific to RubyMotion:
20
+ .dat*
21
+ .repl_history
22
+ build/
23
+ *.bridgesupport
24
+ build-iPhoneOS/
25
+ build-iPhoneSimulator/
26
+
27
+ ## Specific to RubyMotion (use of CocoaPods):
28
+ #
29
+ # We recommend against adding the Pods directory to your .gitignore. However
30
+ # you should judge for yourself, the pros and cons are mentioned at:
31
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
32
+ #
33
+ # vendor/Pods/
34
+
35
+ ## Documentation cache and generated files:
36
+ /.yardoc/
37
+ /_yardoc/
38
+ /doc/
39
+ /rdoc/
40
+
41
+ ## Environment normalization:
42
+ /.bundle/
43
+ /vendor/bundle
44
+ /lib/bundler/man/
45
+
46
+ # for a library or gem, you might want to ignore these files since the code is
47
+ # intended to run in multiple environments; otherwise, check them in:
48
+ # Gemfile.lock
49
+ # .ruby-version
50
+ # .ruby-gemset
51
+
52
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
53
+ .rvmrc
54
+
55
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
56
+ # .rubocop-https?--*
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rspec_status ADDED
@@ -0,0 +1,8 @@
1
+ example_id | status | run_time |
2
+ ------------------------------- | ------- | --------------- |
3
+ ./spec/oreilly_api_spec.rb[1:1] | passed | 0.00057 seconds |
4
+ ./spec/oreilly_api_spec.rb[1:2] | passed | 0.02444 seconds |
5
+ ./spec/oreilly_api_spec.rb[1:3] | passed | 0.00974 seconds |
6
+ ./spec/oreilly_api_spec.rb[1:4] | pending | 0.00001 seconds |
7
+ ./spec/oreilly_api_spec.rb[1:5] | passed | 0.01098 seconds |
8
+ ./spec/oreilly_api_spec.rb[1:6] | passed | 0.00897 seconds |
data/.rubocop.yml ADDED
@@ -0,0 +1 @@
1
+ inherit_from: .rubocop_todo.yml
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,96 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2021-11-26 07:35:05 UTC using RuboCop version 1.23.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Configuration parameters: Include.
11
+ # Include: **/*.gemspec
12
+ Gemspec/RequiredRubyVersion:
13
+ Exclude:
14
+ - 'oreilly_api.gemspec'
15
+
16
+ # Offense count: 1
17
+ # Cop supports --auto-correct.
18
+ # Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment.
19
+ Layout/ExtraSpacing:
20
+ Exclude:
21
+ - 'oreilly_api.gemspec'
22
+
23
+ # Offense count: 1
24
+ # Cop supports --auto-correct.
25
+ Layout/LeadingEmptyLines:
26
+ Exclude:
27
+ - 'oreilly_api.gemspec'
28
+
29
+ # Offense count: 1
30
+ # Cop supports --auto-correct.
31
+ # Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator.
32
+ # SupportedStylesForExponentOperator: space, no_space
33
+ Layout/SpaceAroundOperators:
34
+ Exclude:
35
+ - 'oreilly_api.gemspec'
36
+
37
+ # Offense count: 1
38
+ # Cop supports --auto-correct.
39
+ # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
40
+ # SupportedStyles: space, no_space
41
+ # SupportedStylesForEmptyBraces: space, no_space
42
+ Layout/SpaceInsideBlockBraces:
43
+ Exclude:
44
+ - 'Gemfile'
45
+
46
+ # Offense count: 2
47
+ # Cop supports --auto-correct.
48
+ Style/ExpandPathArguments:
49
+ Exclude:
50
+ - 'oreilly_api.gemspec'
51
+
52
+ # Offense count: 8
53
+ # Cop supports --auto-correct.
54
+ # Configuration parameters: EnforcedStyle.
55
+ # SupportedStyles: always, always_true, never
56
+ Style/FrozenStringLiteralComment:
57
+ Exclude:
58
+ - 'Gemfile'
59
+ - 'Rakefile'
60
+ - 'bin/console'
61
+ - 'lib/oreilly_api.rb'
62
+ - 'lib/oreilly_api/version.rb'
63
+ - 'oreilly_api.gemspec'
64
+ - 'spec/oreilly_api_spec.rb'
65
+ - 'spec/spec_helper.rb'
66
+
67
+ # Offense count: 1
68
+ # Cop supports --auto-correct.
69
+ # Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
70
+ # SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
71
+ Style/HashSyntax:
72
+ Exclude:
73
+ - 'Rakefile'
74
+
75
+ # Offense count: 1
76
+ # Cop supports --auto-correct.
77
+ # Configuration parameters: EnforcedStyle.
78
+ # SupportedStyles: literals, strict
79
+ Style/MutableConstant:
80
+ Exclude:
81
+ - 'lib/oreilly_api/version.rb'
82
+
83
+ # Offense count: 29
84
+ # Cop supports --auto-correct.
85
+ # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
86
+ # SupportedStyles: single_quotes, double_quotes
87
+ Style/StringLiterals:
88
+ Exclude:
89
+ - 'Gemfile'
90
+ - 'Rakefile'
91
+ - 'bin/console'
92
+ - 'lib/oreilly_api.rb'
93
+ - 'lib/oreilly_api/version.rb'
94
+ - 'oreilly_api.gemspec'
95
+ - 'spec/oreilly_api_spec.rb'
96
+ - 'spec/spec_helper.rb'
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.2
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.3.8
7
+ before_install: gem install bundler -v 1.17.3
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at dev@yourmechanic.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,10 @@
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 oreilly_api.gemspec
6
+ gemspec
7
+
8
+ group :test do
9
+ gem 'webmock'
10
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,95 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ oreilly_api (1.0.0)
5
+ byebug
6
+ redis
7
+ redis_utility
8
+ rest-client
9
+ yajl-ruby
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ addressable (2.8.0)
15
+ public_suffix (>= 2.0.2, < 5.0)
16
+ ast (2.4.2)
17
+ byebug (11.1.3)
18
+ crack (0.4.5)
19
+ rexml
20
+ diff-lcs (1.5.0)
21
+ domain_name (0.5.20190701)
22
+ unf (>= 0.0.5, < 1.0.0)
23
+ hashdiff (1.0.1)
24
+ http-accept (1.7.0)
25
+ http-cookie (1.0.5)
26
+ domain_name (~> 0.5)
27
+ mime-types (3.4.1)
28
+ mime-types-data (~> 3.2015)
29
+ mime-types-data (3.2022.0105)
30
+ multi_json (1.15.0)
31
+ netrc (0.11.0)
32
+ parallel (1.22.1)
33
+ parser (3.1.2.0)
34
+ ast (~> 2.4.1)
35
+ public_suffix (4.0.7)
36
+ rainbow (3.1.1)
37
+ rake (13.0.6)
38
+ redis (4.6.0)
39
+ redis_utility (1.0.0)
40
+ regexp_parser (2.5.0)
41
+ rest-client (2.1.0)
42
+ http-accept (>= 1.7.0, < 2.0)
43
+ http-cookie (>= 1.0.2, < 2.0)
44
+ mime-types (>= 1.16, < 4.0)
45
+ netrc (~> 0.8)
46
+ rexml (3.2.5)
47
+ rspec (3.11.0)
48
+ rspec-core (~> 3.11.0)
49
+ rspec-expectations (~> 3.11.0)
50
+ rspec-mocks (~> 3.11.0)
51
+ rspec-core (3.11.0)
52
+ rspec-support (~> 3.11.0)
53
+ rspec-expectations (3.11.0)
54
+ diff-lcs (>= 1.2.0, < 2.0)
55
+ rspec-support (~> 3.11.0)
56
+ rspec-mocks (3.11.1)
57
+ diff-lcs (>= 1.2.0, < 2.0)
58
+ rspec-support (~> 3.11.0)
59
+ rspec-support (3.11.0)
60
+ rubocop (1.30.0)
61
+ parallel (~> 1.10)
62
+ parser (>= 3.1.0.0)
63
+ rainbow (>= 2.2.2, < 4.0)
64
+ regexp_parser (>= 1.8, < 3.0)
65
+ rexml (>= 3.2.5, < 4.0)
66
+ rubocop-ast (>= 1.18.0, < 2.0)
67
+ ruby-progressbar (~> 1.7)
68
+ unicode-display_width (>= 1.4.0, < 3.0)
69
+ rubocop-ast (1.18.0)
70
+ parser (>= 3.1.1.0)
71
+ ruby-progressbar (1.11.0)
72
+ unf (0.1.4)
73
+ unf_ext
74
+ unf_ext (0.0.8.2)
75
+ unicode-display_width (2.1.0)
76
+ webmock (3.14.0)
77
+ addressable (>= 2.8.0)
78
+ crack (>= 0.3.2)
79
+ hashdiff (>= 0.4.0, < 2.0.0)
80
+ yajl-ruby (1.4.3)
81
+
82
+ PLATFORMS
83
+ x86_64-darwin-19
84
+
85
+ DEPENDENCIES
86
+ bundler (~> 2.2.8)
87
+ multi_json
88
+ oreilly_api!
89
+ rake (~> 13.0)
90
+ rspec (~> 3.0)
91
+ rubocop (~> 1.7)
92
+ webmock
93
+
94
+ BUNDLED WITH
95
+ 2.2.33
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 YourMechanic
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # OreillyApi
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/oreilly_api`. 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 'oreilly_api'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install oreilly_api
22
+
23
+ ## Usage
24
+
25
+ After installing the gem create a file oreilly.rb in config/initializers with following content:
26
+
27
+ ```ruby
28
+ OreillyApi.config do |c|
29
+ c.domain = 'https://sms-test-1.firstcallonline.com'
30
+ c.client_id = 'client_id'
31
+ c.client_secret = 'client_sercet'
32
+ c.identity = 'IDENTITY'
33
+ c.version = 'sms-external-partner/services'
34
+ c.account_number = '123456'
35
+ end
36
+ ```
37
+
38
+ to Place an Order
39
+ ```ruby
40
+ OreillyApi.place_order(payload)
41
+ ```
42
+
43
+ to Fetch Quote
44
+ ```ruby
45
+ OreillyApi.fetch_quote(items)
46
+ ```
47
+
48
+
49
+ to get sample requuest
50
+ ```ruby
51
+ OreillyApi.sample_request
52
+ ```
53
+
54
+ to test place order
55
+ ```ruby
56
+ OreillyApi.test_place_order
57
+ ```
58
+
59
+ ## Development
60
+
61
+ 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.
62
+
63
+ 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).
64
+
65
+ ## Contributing
66
+
67
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/oreilly_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
68
+
69
+ ## License
70
+
71
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
72
+
73
+ ## Code of Conduct
74
+
75
+ Everyone interacting in the OreillyApi project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/oreilly_api/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
8
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "oreilly_api"
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__)
data/bin/setup ADDED
@@ -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,3 @@
1
+ module OreillyApi
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,124 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "oreilly_api/version"
4
+ require 'base64'
5
+ require 'json'
6
+ require 'rest-client'
7
+ require 'redis'
8
+ require 'redis_utility'
9
+
10
+ # rubocop:disable Metrics/MethodLength
11
+
12
+ # OreillyApi
13
+ module OreillyApi
14
+ TOKEN = 'oreilly_api_token'
15
+ class << self
16
+ attr_accessor :domain, :version, :client_id, :client_secret, :identity, :account_number
17
+
18
+ def config
19
+ yield self
20
+ end
21
+
22
+ def redis_utility=(redis_config)
23
+ RedisUtility.redis_config = redis_config
24
+ end
25
+
26
+ def payload_id
27
+ "YM#{OreillyApi.account_number}#{DateTime.now.strftime('%Y%m%d%l%S%M')}}"
28
+ end
29
+
30
+ def place_order(po_number, vehicles_with_items, stop_order: false)
31
+ payload = {
32
+ 'header' => {
33
+ 'identity' => OreillyApi.identity,
34
+ 'payloadId' => OreillyApi.payload_id,
35
+ 'timestamp' => Time.now.strftime("%Y-%m-%d %H:%M:%S")
36
+ },
37
+ 'orderHeader' => {
38
+ 'poNumber' => po_number,
39
+ 'accountNumber' => OreillyApi.account_number,
40
+ 'comments' => "test"
41
+ },
42
+ 'vehicles' => vehicles_with_items
43
+ }.to_json
44
+ url = "#{base_url}/order/placeOrder?stopOrder=#{stop_order}"
45
+ token = fetch_token
46
+ res = RestClient.post(url, payload, get_header(token))
47
+ place_order_response = JSON.parse(res)
48
+ [res.code, place_order_response]
49
+ end
50
+
51
+ def fetch_quote(items)
52
+ payload = {
53
+ 'accountNumber' => OreillyApi.account_number,
54
+ 'header' => {
55
+ 'identity' => OreillyApi.identity,
56
+ 'payloadId' => OreillyApi.payload_id,
57
+ 'timestamp' => Time.now.strftime("%Y-%m-%d %H:%M:%S")
58
+ },
59
+ 'items' => items
60
+ }.to_json
61
+ url = "#{base_url}/quote/fetchQuote"
62
+ token = fetch_token
63
+ res = RestClient.post(url, payload, get_header(token))
64
+ sample_request = JSON.parse(res)
65
+ [res.code, sample_request]
66
+ end
67
+
68
+ def sample_request
69
+ token = fetch_token
70
+ url = "#{base_url}/quote/sampleRequest?detailsRequired=false"
71
+ res = RestClient.get(url, get_header(token))
72
+ sample_request = JSON.parse(res)
73
+ [res.code, sample_request]
74
+ end
75
+
76
+ def test_place_order
77
+ token = fetch_token
78
+ url = "#{base_url}/order/testPlaceOrder?detailsRequired=false"
79
+ res = RestClient.get(url, get_header(token))
80
+ place_order_response = JSON.parse(res)
81
+ [res.code, place_order_response]
82
+ end
83
+
84
+ def invoice(order_number)
85
+ token = fetch_token
86
+
87
+ params = "identity=#{OreillyApi.identity}&orderDetails=true&orderNumber=#{order_number}"
88
+ url = "#{base_url}/order/invoice?#{params}"
89
+ res = RestClient.get(url, get_header(token))
90
+ invoice_info = JSON.parse(res)
91
+ [res.code, invoice_info]
92
+ end
93
+
94
+ private
95
+
96
+ def fetch_token
97
+ oreilly_api_token = RedisUtility.redis.get(OreillyApi::TOKEN) || ''
98
+ return oreilly_api_token unless oreilly_api_token.empty?
99
+
100
+ payload = {
101
+ 'header' => {
102
+ 'identity' => OreillyApi.identity
103
+ }
104
+ }.to_json
105
+
106
+ params = "&client_id=#{OreillyApi.client_id}&client_secret=#{OreillyApi.client_secret}"
107
+ url = "#{OreillyApi.domain}/oauth-server/oauth/token?grant_type=client_credentials&device_id=test#{params}"
108
+ res = RestClient.post(url, payload, { 'Content-Type' => 'application/json' })
109
+ token_info = JSON.parse(res)
110
+ @token = token_info['access_token']
111
+ RedisUtility.redis.setex(OreillyApi::TOKEN, 119, @token)
112
+ @token
113
+ end
114
+
115
+ def get_header(token)
116
+ { 'Authorization' => "Bearer #{token}", 'Content-Type' => 'application/json' }
117
+ end
118
+
119
+ def base_url
120
+ "#{OreillyApi.domain}/#{OreillyApi.version}"
121
+ end
122
+ end
123
+ # rubocop:enable Metrics/MethodLength
124
+ end
@@ -0,0 +1,48 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "oreilly_api/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "oreilly_api"
8
+ spec.version = OreillyApi::VERSION
9
+ spec.authors = ["TruptiHosmani"]
10
+ spec.email = ["dev@yourmechanic.com"]
11
+
12
+ spec.summary = "Gem to integrate O'Reilly Auto Parts Rest API"
13
+ spec.description = "This gem provides a simple way to integrate O'Reilly Auto Parts Rest Apis"
14
+ spec.homepage = "https://github.com/YourMechanic/oreilly_api"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+
22
+ spec.metadata["homepage_uri"] = spec.homepage
23
+ spec.metadata["source_code_uri"] = "https://github.com/YourMechanic/oreilly_api"
24
+ else
25
+ raise "RubyGems 2.0 or newer is required to protect against " \
26
+ "public gem pushes."
27
+ end
28
+
29
+ # Specify which files should be added to the gem when it is released.
30
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
32
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
+ end
34
+ spec.bindir = "exe"
35
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
+ spec.require_paths = ["lib"]
37
+
38
+ spec.add_development_dependency 'bundler', '~> 2.2.8'
39
+ spec.add_development_dependency 'rake', '~> 13.0'
40
+ spec.add_development_dependency 'rspec', '~> 3.0'
41
+ spec.add_development_dependency 'rubocop', '~> 1.7'
42
+ spec.add_dependency 'byebug'
43
+ spec.add_dependency 'redis'
44
+ spec.add_dependency 'redis_utility'
45
+ spec.add_dependency 'rest-client'
46
+ spec.add_dependency 'yajl-ruby'
47
+ spec.add_development_dependency 'multi_json'
48
+ end
metadata ADDED
@@ -0,0 +1,206 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oreilly_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - TruptiHosmani
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-06-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.2.8
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.2.8
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: redis
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: redis_utility
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rest-client
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
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: yajl-ruby
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: multi_json
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: This gem provides a simple way to integrate O'Reilly Auto Parts Rest
154
+ Apis
155
+ email:
156
+ - dev@yourmechanic.com
157
+ executables: []
158
+ extensions: []
159
+ extra_rdoc_files: []
160
+ files:
161
+ - ".circleci/config.yml"
162
+ - ".gitignore"
163
+ - ".rspec"
164
+ - ".rspec_status"
165
+ - ".rubocop.yml"
166
+ - ".rubocop_todo.yml"
167
+ - ".ruby-version"
168
+ - ".travis.yml"
169
+ - CODE_OF_CONDUCT.md
170
+ - Gemfile
171
+ - Gemfile.lock
172
+ - LICENSE
173
+ - README.md
174
+ - Rakefile
175
+ - bin/console
176
+ - bin/setup
177
+ - lib/oreilly_api.rb
178
+ - lib/oreilly_api/version.rb
179
+ - oreilly_api.gemspec
180
+ homepage: https://github.com/YourMechanic/oreilly_api
181
+ licenses:
182
+ - MIT
183
+ metadata:
184
+ allowed_push_host: https://rubygems.org
185
+ homepage_uri: https://github.com/YourMechanic/oreilly_api
186
+ source_code_uri: https://github.com/YourMechanic/oreilly_api
187
+ post_install_message:
188
+ rdoc_options: []
189
+ require_paths:
190
+ - lib
191
+ required_ruby_version: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - ">="
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ required_rubygems_version: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - ">="
199
+ - !ruby/object:Gem::Version
200
+ version: '0'
201
+ requirements: []
202
+ rubygems_version: 3.0.3
203
+ signing_key:
204
+ specification_version: 4
205
+ summary: Gem to integrate O'Reilly Auto Parts Rest API
206
+ test_files: []