fuelscropt-api-client 0.3.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cb541aa0e46ccb5b7d0e0de3cfcd456e32005657500f7920ea9cec2f46b01f3a
4
+ data.tar.gz: 5da5660467e0674cfd6cb1a6eea8c1d4db2165217a859aa1c7e358120f9f85d2
5
+ SHA512:
6
+ metadata.gz: 50e5c99360e1cd199469d793ef879043ca45963e29494fe5b7fe179438b66164be5c4f0070396f8c678b541c8a9d5b8e96e3dc0cf20d6553968ad3f8f95509ad
7
+ data.tar.gz: '0389a43fc2515155689e33fd376014b4838ad7a8864ea9b17ec6d98a898d99ca5afbf5db0d6c4e54ef010744e868e6ecf891cdcefb69f65f1928d02e397bd92c'
data/.gitignore ADDED
@@ -0,0 +1,15 @@
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
12
+
13
+ /demo
14
+ *.gem
15
+ *.gemspec
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.3
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in fullscriptapi.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,36 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fullscriptapi (0.2.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.4.4)
10
+ excon (0.85.0)
11
+ rake (12.3.3)
12
+ rspec (3.10.0)
13
+ rspec-core (~> 3.10.0)
14
+ rspec-expectations (~> 3.10.0)
15
+ rspec-mocks (~> 3.10.0)
16
+ rspec-core (3.10.1)
17
+ rspec-support (~> 3.10.0)
18
+ rspec-expectations (3.10.1)
19
+ diff-lcs (>= 1.2.0, < 2.0)
20
+ rspec-support (~> 3.10.0)
21
+ rspec-mocks (3.10.2)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.10.0)
24
+ rspec-support (3.10.3)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ excon (~> 0.85.0)
31
+ fullscriptapi!
32
+ rake (~> 12.0)
33
+ rspec (~> 3.0)
34
+
35
+ BUNDLED WITH
36
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 TODO: Write your name
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.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # Fullscriptapi
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/fullscriptapi`. 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 'fullscriptapi'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install fullscriptapi
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]/fullscriptapi.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fullscriptapi"
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,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fullscriptapi
4
+ class AccessToken
5
+ attr_reader :client, :access_token, :expires_in, :expires_at
6
+ attr_accessor :refresh_token
7
+
8
+ def initialize(opts = {})
9
+ opts = opts.dup
10
+
11
+ %i[access_token refresh_token expires_in expires_at expires_latency].each do |arg|
12
+ instance_variable_set("@#{arg}", opts.delete(arg) || opts.delete(arg.to_s))
13
+ end
14
+
15
+ @expires_in ||= opts.delete('expires')
16
+ @expires_in &&= @expires_in.to_i
17
+ @expires_at &&= convert_expires_at(@expires_at)
18
+ @expires_at ||= Time.now.to_i + @expires_in if @expires_in
19
+ end
20
+
21
+ def expired?
22
+ expires_at <= Time.now.to_i
23
+ end
24
+
25
+ private
26
+ def convert_expires_at(expires_at)
27
+ Time.iso8601(expires_at.to_s).to_i
28
+ rescue ArgumentError
29
+ expires_at.to_i
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fullscriptapi
4
+ module Endpoints
5
+ module CreateAnOauthToken
6
+ def create_an_oauth_token(grant)
7
+ # you need to have an auth grant to use this method
8
+
9
+ raise unless client_id && secret && redirect_uri
10
+
11
+ response = Excon.post("#{get_server}/oauth/token",
12
+ headers: {
13
+ "Content-Type": "application/json"
14
+ },
15
+ body: {
16
+ grant_type: "authorization_code",
17
+ client_id: client_id,
18
+ client_secret: secret,
19
+ code: grant,
20
+ redirect_uri: redirect_uri
21
+ }.to_json
22
+ )
23
+
24
+ body = JSON.parse(response.body)
25
+
26
+ use_token(body["oauth"])
27
+
28
+ body
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fullscriptapi
4
+ module Endpoints
5
+ module ListAllProducts
6
+ def list_all_products
7
+ refresh_token if stale_token? #to do: add logic to conditionally refresh token
8
+
9
+ Excon.get("#{get_server}/catalog/products",
10
+ headers: {
11
+ "Content-Type": "application/json",
12
+ "Authorization": "Bearer #{token.access_token}"
13
+ }
14
+ )
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fullscriptapi
4
+ module Endpoints
5
+ module RefreshToken
6
+ def refresh_token
7
+ response = Excon.post("#{get_server}/oauth/token",
8
+ headers: {
9
+ "Content-Type": "application/json"
10
+ },
11
+ body: {
12
+ grant_type: "refresh_token",
13
+ client_id: client_id,
14
+ client_secret: secret,
15
+ redirect_uri: redirect_uri,
16
+ refresh_token: token.refresh_token
17
+ }.to_json
18
+ )
19
+
20
+ body = JSON.parse(response.body)
21
+
22
+ pp body
23
+ use_token(body["oauth"])
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'endpoints/list_all_products'
4
+ require_relative 'endpoints/create_an_oauth_token'
5
+ require_relative 'endpoints/refresh_token'
6
+
7
+ module Fullscriptapi
8
+ module Endpoints
9
+ include ListAllProducts
10
+ include CreateAnOauthToken
11
+ include RefreshToken
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Fullscriptapi
2
+ VERSION = "0.3.2"
3
+ end
@@ -0,0 +1,44 @@
1
+ require_relative "fullscriptapi/version"
2
+ require_relative "fullscriptapi/access_token"
3
+ require_relative "fullscriptapi/endpoints"
4
+ require 'excon'
5
+ require 'json'
6
+
7
+ module Fullscriptapi
8
+ class << self
9
+ include Fullscriptapi::Endpoints
10
+
11
+ attr_accessor :client_id, :secret, :redirect_uri, :token, :server
12
+
13
+ def config
14
+ yield self if block_given?
15
+
16
+ self
17
+ end
18
+ alias :new :config
19
+
20
+ def use_token(opts = {})
21
+ # pass in a hash containing token attributes e.g. access_token, refresh_token, expires_*
22
+ @token = Fullscriptapi::AccessToken.new(opts)
23
+ end
24
+
25
+ private
26
+ def get_server
27
+ servers["#{server}"]
28
+ end
29
+
30
+ def servers
31
+ {
32
+ "dev" => "http://localhost:3000/api",
33
+ "us_snd" => "https://api-us-snd.fullscript.io/api/",
34
+ "ca_snd" => "https://api-ca-snd.fullscript.io/api/",
35
+ "us_prod" => "https://api-us.fullscript.io/api/",
36
+ "ca_prod" => "https://api-ca.fullscript.io/api/"
37
+ }
38
+ end
39
+
40
+ def stale_token?
41
+ token && token.expired?
42
+ end
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fuelscropt-api-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.2
5
+ platform: ruby
6
+ authors:
7
+ - Theodore Ambie-Barango
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-12-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: excon
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.85.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.85.0
27
+ description: This gem is designed to help consumers of the Fullscript API to be able
28
+ to easily complete their builds.
29
+ email:
30
+ - theodore.ambiebarango@fullscript.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - ".rspec"
37
+ - ".travis.yml"
38
+ - Gemfile
39
+ - Gemfile.lock
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - bin/console
44
+ - bin/setup
45
+ - lib/fullscriptapi.rb
46
+ - lib/fullscriptapi/access_token.rb
47
+ - lib/fullscriptapi/endpoints.rb
48
+ - lib/fullscriptapi/endpoints/create_an_oauth_token.rb
49
+ - lib/fullscriptapi/endpoints/list_all_products.rb
50
+ - lib/fullscriptapi/endpoints/refresh_token.rb
51
+ - lib/fullscriptapi/version.rb
52
+ homepage: https://github.com/Tambiebarango/fs-api-gem
53
+ licenses:
54
+ - MIT
55
+ metadata:
56
+ allowed_push_host: https://rubygems.org
57
+ homepage_uri: https://github.com/Tambiebarango/fs-api-gem
58
+ source_code_uri: https://github.com/Tambiebarango/fs-api-gem
59
+ changelog_uri: https://github.com/Tambiebarango/fs-api-gem
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 2.3.0
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubygems_version: 3.0.3
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: This gem is designed to help consumers of the Fullscript API to be able to
79
+ easily complete their builds.
80
+ test_files: []