fulfil-io 0.1.0 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 95fb599e7f5a781ab44fb3026f108c1e9952caad1f6db580989e915c2b9498f6
4
- data.tar.gz: 8c56400a193b6ef8de6b60588dd793213b794fe9dc4959068402b4a0816ea4e1
3
+ metadata.gz: d1e18bf38ef0d20058704b439d3b633cd2a2d6c36d6eb3498764473ecdc18542
4
+ data.tar.gz: ef37d25469b610f6d1d7ef4e1ef41e681b514f39d147e652338464fd9a2fb977
5
5
  SHA512:
6
- metadata.gz: 577b1cb9f71d27cfa533fd8dce8db1e6491f0c9ac8e798b412c6f454ac64879b6ca9e9de86d87670ece787047295d74e533f15d5de343fc0820fd9dfc6aa3a62
7
- data.tar.gz: 579ccb9a08afe4c30c2ad9d8627c8f941b6b0f03da5a6397c13f3264061aae227777d7c0929c36dd08b56e53839802a8d3dbbaa2dc73ec65278cc59613501c5c
6
+ metadata.gz: d33dc2d8553c14c08284d6823bd0285c28bb168785e9c9885cfd9718e8233d804860348cd7ea2bcec56141de976153bd605dfabab4ce73ce958a4935abc9a17d
7
+ data.tar.gz: 634d58e4e9780873f4ff9c1823ab8fb1a08de125e6906ed48d50773b838015e7ea4cf8abd65ee3df26f035eab6a1131ab75a56511b3f55400e2b67f17a7b42f0
@@ -1,3 +1,39 @@
1
+ ## 0.4.3
2
+
3
+ * Add Client errors for more granular handling.
4
+ * Send along info when a `NotAuthorizedError` is raised.
5
+
6
+ ## 0.4.2
7
+
8
+ * Raise an `UnhandledTypeError` and reveal the offender.
9
+ * Convert timedelta data types to Decimals.
10
+ * Don't use `.present?` to check if response is a Hash.
11
+
12
+ ## 0.4.1
13
+
14
+ * @cdmwebs screwed up the release process, so this is a tiny bump to fix. No
15
+ code changes.
16
+
17
+ ## 0.4.0
18
+
19
+ * Add `Client#count` and `Model#count`.
20
+
21
+ ## 0.3.0
22
+
23
+ * Add basic write support via `Fulfil::Client#post` and `Fulfil::Client#put`.
24
+
25
+ ## 0.2.0
26
+
27
+ * Make token optional and allow specifying headers at least for enabling
28
+ authentication via 'X-API-KEY' header , because initially implemented in
29
+ 0.1.0 bearer auth isn't working.
30
+ * Fix Query `build_search_term` and `build_exclude_term` to be compatible with
31
+ Ruby < 2.4, analyzing value for 'Fixnum ' class.
32
+ * Fix the gem's name in gemspec to 'fulfil-io', as registered at RubyGems.
33
+ * Remove Rake version constraint from gemspec.
34
+ * Add Gemfile.lock to .gitignore and remove it from git-tree - it shouldn't be
35
+ stored in git for a gem.
36
+
1
37
  ## 0.1.0
2
38
 
3
- * Initial gem release
39
+ * Initial gem release.
data/README.md CHANGED
@@ -9,30 +9,33 @@
9
9
  Add this line to your application's Gemfile:
10
10
 
11
11
  ```ruby
12
- gem 'fulfil'
12
+ gem 'fulfil-io', require: 'fulfil'
13
13
  ```
14
14
 
15
15
  And then execute:
16
16
 
17
- $ bundle
17
+ $ bundle install
18
18
 
19
19
  Or install it yourself as:
20
20
 
21
- $ gem install fulfil
21
+ $ gem install fulfil-io
22
22
 
23
23
  ## Usage
24
24
 
25
- ```ruby
26
- require 'fulfil'
25
+ Environment variables:
27
26
 
28
- FULFIL_SUBDOMAIN = 'subdomain'
29
- FULFIL_TOKEN = 'token'
27
+ - FULFIL_SUBDOMAIN - required to be set.
28
+ - FULFIL_TOKEN - required for oauth bearer authentication
29
+ - FULFIL_API_KEY - required for authentication via the X-API-KEY request header
30
30
 
31
- fulfil = Fulfil::Client.new(
32
- subdomain: FULFIL_SUBDOMAIN,
33
- token: FULFIL_TOKEN,
34
- debug: false
35
- )
31
+ **Note:** When FULFIL_TOKEN is present, the FULFIL_API_KEY will be ignored. So,
32
+ if oauth doesn't work, returning an Unauthorized error, to use the
33
+ FULFIL_API_KEY, the FULFIL_TOKEN shouldn't be specified.
34
+
35
+ ```ruby
36
+ require 'fulfil' # this is necessary only in case of running without bundler
37
+
38
+ fulfil = Fulfil::Client.new # or, to enable request debugging, Fulfil::Client.new(debug: true)
36
39
 
37
40
  sale_model = Fulfil::Model.new(
38
41
  client: fulfil,
@@ -65,6 +68,48 @@ pp sales
65
68
  # "rec_name"=>""}]
66
69
  ```
67
70
 
71
+ ### Count
72
+
73
+ ```ruby
74
+ client = Fulfil::Client.new
75
+ model = Fulfil::Model.new(client: client, model_name: 'stock.shipment.out')
76
+ model.count(domain: [['shipping_batch.state', '=', 'open']])
77
+
78
+ # Returns 7440
79
+ ```
80
+
81
+ ### Writing
82
+
83
+ As of v0.3.0, we've added very basic support for creates and updates via
84
+ `Fulfil::Client#post` and `Fulfil::Client#put`.
85
+
86
+ *Create Example*
87
+
88
+ ```ruby
89
+ fulfil = Fulfil::Client.new
90
+
91
+ sale_model = Fulfil::Model.new(client: fulfil, model_name: 'sale.sale')
92
+
93
+ sale = {
94
+ # Full Sale attributes here
95
+ }
96
+
97
+ fulfil.post(model: sale_model, body: sale)
98
+ ```
99
+
100
+ *Update Example*
101
+
102
+ ```ruby
103
+ fulfil = Fulfil::Client.new
104
+
105
+ sale_model = Fulfil::Model.new(client: fulfil, model_name: 'sale.sale')
106
+ sale = sale_model.find(id: 1234)
107
+
108
+ sale['channel'] = 4
109
+
110
+ fulfil.put(model: sale_model, body: sale)
111
+ ```
112
+
68
113
  ## Development
69
114
 
70
115
  After checking out the repo, run `bin/setup` to install dependencies. Then, run
@@ -5,11 +5,22 @@ require 'logger'
5
5
  require 'fulfil/response_parser'
6
6
 
7
7
  module Fulfil
8
+ SUBDOMAIN = ENV['FULFIL_SUBDOMAIN']
9
+ API_KEY = ENV['FULFIL_API_KEY']
10
+ OAUTH_TOKEN = ENV['FULFIL_TOKEN']
11
+
8
12
  class Client
9
- def initialize(subdomain:, token:, debug: false)
13
+ class NotAuthorizedError < StandardError; end
14
+ class UnknownHTTPError < StandardError; end
15
+ class ConnectionError < StandardError; end
16
+ class ResponseError < StandardError; end
17
+
18
+ def initialize(subdomain: SUBDOMAIN, token: OAUTH_TOKEN, headers: { 'X-API-KEY' => API_KEY }, debug: false)
10
19
  @subdomain = subdomain
11
20
  @token = token
12
21
  @debug = debug
22
+ @headers = headers
23
+ @headers.delete('X-API-KEY') if @token
13
24
  end
14
25
 
15
26
  def find(model:, ids: [], id: nil, fields: %w[id rec_name])
@@ -38,9 +49,7 @@ module Fulfil
38
49
  parse(results: results)
39
50
  end
40
51
 
41
- def search(
42
- model:, domain:, offset: nil, limit: 100, sort: nil, fields: %w[id]
43
- )
52
+ def search(model:, domain:, offset: nil, limit: 100, sort: nil, fields: %w[id])
44
53
  uri = URI("#{model_url(model: model)}/search_read")
45
54
  body = [domain, offset, limit, sort, fields]
46
55
 
@@ -48,6 +57,13 @@ module Fulfil
48
57
  parse(results: results)
49
58
  end
50
59
 
60
+ def count(model:, domain:)
61
+ uri = URI("#{model_url(model: model)}/search_count")
62
+ body = [domain]
63
+
64
+ request(verb: :put, endpoint: uri, json: body)
65
+ end
66
+
51
67
  def post(model:, body: {})
52
68
  uri = URI(model_url(model: model))
53
69
 
@@ -55,9 +71,28 @@ module Fulfil
55
71
  parse(results: results)
56
72
  end
57
73
 
74
+ def put(model:, id:, endpoint: nil, body: {})
75
+ uri = URI(model_url(model: model, id: id, endpoint: endpoint))
76
+
77
+ result = request(verb: :put, endpoint: uri, json: body)
78
+ parse(result: result)
79
+ end
80
+
58
81
  private
59
82
 
60
83
  def parse(result: nil, results: [])
84
+ if result
85
+ parse_single(result: result)
86
+ else
87
+ parse_multiple(results: results)
88
+ end
89
+ end
90
+
91
+ def parse_single(result:)
92
+ Fulfil::ResponseParser.parse(item: result)
93
+ end
94
+
95
+ def parse_multiple(results:)
61
96
  results.map { |result| Fulfil::ResponseParser.parse(item: result) }
62
97
  end
63
98
 
@@ -65,8 +100,8 @@ module Fulfil
65
100
  "https://#{@subdomain}.fulfil.io/api/v2/model"
66
101
  end
67
102
 
68
- def model_url(model:)
69
- [base_url, model].join('/')
103
+ def model_url(model:, id: nil, endpoint: nil)
104
+ [base_url, model, id, endpoint].compact.join('/')
70
105
  end
71
106
 
72
107
  def request(verb: :get, endpoint:, **args)
@@ -75,26 +110,30 @@ module Fulfil
75
110
  if response.status.ok? || response.status.created?
76
111
  response.parse
77
112
  elsif response.code == 401
78
- raise StandardError, 'Not authorized'
113
+ error = response.parse
114
+ raise NotAuthorizedError, "Not authorized: #{error['error']}: #{error['error_description']}"
79
115
  else
80
116
  puts response.body.to_s
81
117
  raise Error, 'Error encountered while processing response:'
82
118
  end
83
119
  rescue HTTP::Error => e
84
120
  puts e
85
- raise Error, 'Unhandled HTTP error encountered'
121
+ raise UnknownHTTPError, 'Unhandled HTTP error encountered'
86
122
  rescue HTTP::ConnectionError => e
87
123
  puts "Couldn't connect"
88
- raise Error, "Can't connect to #{base_url}"
89
- rescue HTTP::ResponseError => e
90
- raise Error, "Can't process response: #{e}"
124
+ raise ConnectionError, "Can't connect to #{base_url}"
125
+ rescue HTTP::ResponseError => ex
126
+ raise ResponseError, "Can't process response: #{ex}"
91
127
  []
92
128
  end
93
129
 
94
130
  def client
95
- @client ||=
96
- HTTP.persistent(base_url).auth("Bearer #{@token}")
97
- .use(logging: @debug ? { logger: Logger.new(STDOUT) } : {})
131
+ return @client if defined?(@client)
132
+
133
+ @client = HTTP.persistent(base_url).use(logging: @debug ? { logger: Logger.new(STDOUT) } : {})
134
+ @client = @client.auth("Bearer #{@token}") if @token
135
+ @client = @client.headers(@headers)
136
+ @client
98
137
  end
99
138
  end
100
139
  end
@@ -36,6 +36,10 @@ module Fulfil
36
36
  )
37
37
  end
38
38
 
39
+ def count(domain:)
40
+ @client.count(model: model_name, domain: domain)
41
+ end
42
+
39
43
  def all
40
44
  search(domain: query)
41
45
  end
@@ -68,7 +68,7 @@ module Fulfil
68
68
  case value.class.name
69
69
  when 'Array'
70
70
  [[key, 'in', value]]
71
- when 'Integer'
71
+ when 'Fixnum', 'Integer'
72
72
  [[key, '=', value]]
73
73
  when 'Range'
74
74
  [
@@ -96,7 +96,7 @@ module Fulfil
96
96
  case value.class.name
97
97
  when 'Array'
98
98
  [[key, 'not in', value]]
99
- when 'Integer'
99
+ when 'Fixnum', 'Integer'
100
100
  [[key, '!=', value]]
101
101
  when 'Range'
102
102
  [
@@ -112,4 +112,4 @@ module Fulfil
112
112
  end
113
113
  end
114
114
  end
115
- end
115
+ end
@@ -1,5 +1,14 @@
1
1
  module Fulfil
2
2
  module ResponseParser
3
+ class UnhandledTypeError < StandardError
4
+ attr_reader :value
5
+
6
+ def initialize(msg, value)
7
+ @value = value
8
+ super(msg)
9
+ end
10
+ end
11
+
3
12
  # Handle value objects, for example:
4
13
  #
5
14
  # "order_date": {
@@ -19,10 +28,13 @@ module Fulfil
19
28
  when 'datetime'
20
29
  time = value.dig('iso_string')
21
30
  DateTime.parse(time)
22
- when 'Decimal'
31
+ when 'Decimal', 'timedelta'
23
32
  value.dig('decimal').to_f
24
33
  else
25
- raise UnhandledTypeError, value
34
+ raise UnhandledTypeError.new(
35
+ "received a value that we don't know how to handle: #{json_class}",
36
+ json_class
37
+ )
26
38
  end
27
39
  end
28
40
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Fulfil
2
- VERSION = "0.1.0"
4
+ VERSION = '0.4.3'
3
5
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fulfil-io
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Moore
8
8
  - Kat Fairbanks
9
- autorequire:
10
- bindir: exe
9
+ autorequire:
10
+ bindir: bin
11
11
  cert_chain: []
12
- date: 2020-06-25 00:00:00.000000000 Z
12
+ date: 2020-11-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: http
@@ -85,37 +85,30 @@ dependencies:
85
85
  name: rake
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
- - - "~>"
88
+ - - ">="
89
89
  - !ruby/object:Gem::Version
90
- version: '10.0'
90
+ version: '0'
91
91
  type: :development
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
- - - "~>"
95
+ - - ">="
96
96
  - !ruby/object:Gem::Version
97
- version: '10.0'
98
- description:
97
+ version: '0'
98
+ description:
99
99
  email:
100
100
  - chris@knowndecimal.com
101
101
  executables: []
102
102
  extensions: []
103
- extra_rdoc_files: []
103
+ extra_rdoc_files:
104
+ - README.md
105
+ - CHANGELOG.md
106
+ - LICENSE.txt
104
107
  files:
105
- - ".circleci/config.yml"
106
- - ".gitignore"
107
- - ".travis.yml"
108
108
  - CHANGELOG.md
109
- - CODE_OF_CONDUCT.md
110
- - Gemfile
111
- - Gemfile.lock
112
109
  - LICENSE.txt
113
110
  - README.md
114
111
  - Rakefile
115
- - bin/authenticate
116
- - bin/console
117
- - bin/setup
118
- - fulfil.gemspec
119
112
  - lib/fulfil.rb
120
113
  - lib/fulfil/client.rb
121
114
  - lib/fulfil/model.rb
@@ -126,7 +119,7 @@ homepage: https://github.com/knowndecimal/fulfil
126
119
  licenses:
127
120
  - MIT
128
121
  metadata: {}
129
- post_install_message:
122
+ post_install_message:
130
123
  rdoc_options: []
131
124
  require_paths:
132
125
  - lib
@@ -134,7 +127,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
134
127
  requirements:
135
128
  - - ">="
136
129
  - !ruby/object:Gem::Version
137
- version: '0'
130
+ version: 2.3.0
138
131
  required_rubygems_version: !ruby/object:Gem::Requirement
139
132
  requirements:
140
133
  - - ">="
@@ -142,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
135
  version: '0'
143
136
  requirements: []
144
137
  rubygems_version: 3.0.3
145
- signing_key:
138
+ signing_key:
146
139
  specification_version: 4
147
140
  summary: Interact with the Fulfil.io API
148
141
  test_files: []
@@ -1,43 +0,0 @@
1
- version: 2
2
- jobs:
3
- build:
4
- docker:
5
- - image: circleci/ruby:2.6.0
6
- working_directory: ~/repo
7
-
8
- steps:
9
- - checkout
10
-
11
- # Download and cache dependencies
12
- - restore_cache:
13
- keys:
14
- - v1-dependencies-{{ checksum "Gemfile.lock" }}
15
- # fallback to using the latest cache if no exact match is found
16
- - v1-dependencies-
17
-
18
- - run:
19
- name: install dependencies
20
- command: |
21
- gem install bundler --no-document
22
- bundle install --jobs=4 --retry=3 --path vendor/bundle
23
-
24
- - save_cache:
25
- paths:
26
- - ./vendor/bundle
27
- key: v1-dependencies-{{ checksum "Gemfile.lock" }}
28
-
29
- # run tests!
30
- - run:
31
- name: run tests
32
- environment:
33
- TESTOPTS: "--ci-dir=/tmp/test-results"
34
- command: |
35
- mkdir /tmp/test-results
36
- bundle exec rake test
37
-
38
- # collect reports
39
- - store_test_results:
40
- path: /tmp/test-results
41
- - store_artifacts:
42
- path: /tmp/test-results
43
- destination: test-results
data/.gitignore DELETED
@@ -1,8 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
@@ -1,7 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.6.1
7
- before_install: gem install bundler -v 2.0.1
@@ -1,74 +0,0 @@
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 chris@cdmwebs.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 DELETED
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- gemspec
@@ -1,63 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- fulfil (0.1.0)
5
- http
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- addressable (2.6.0)
11
- public_suffix (>= 2.0.2, < 4.0)
12
- ansi (1.5.0)
13
- builder (3.2.3)
14
- domain_name (0.5.20190701)
15
- unf (>= 0.0.5, < 1.0.0)
16
- faraday (0.17.1)
17
- multipart-post (>= 1.2, < 3)
18
- http (4.1.1)
19
- addressable (~> 2.3)
20
- http-cookie (~> 1.0)
21
- http-form_data (~> 2.0)
22
- http_parser.rb (~> 0.6.0)
23
- http-cookie (1.0.3)
24
- domain_name (~> 0.5)
25
- http-form_data (2.1.1)
26
- http_parser.rb (0.6.0)
27
- jwt (2.2.1)
28
- minitest (5.11.3)
29
- minitest-reporters (1.3.6)
30
- ansi
31
- builder
32
- minitest (>= 5.0)
33
- ruby-progressbar
34
- multi_json (1.14.1)
35
- multi_xml (0.6.0)
36
- multipart-post (2.1.1)
37
- oauth2 (1.4.2)
38
- faraday (>= 0.8, < 2.0)
39
- jwt (>= 1.0, < 3.0)
40
- multi_json (~> 1.3)
41
- multi_xml (~> 0.5)
42
- rack (>= 1.2, < 3)
43
- public_suffix (3.1.1)
44
- rack (2.0.7)
45
- rake (10.5.0)
46
- ruby-progressbar (1.10.1)
47
- unf (0.1.4)
48
- unf_ext
49
- unf_ext (0.0.7.6)
50
-
51
- PLATFORMS
52
- ruby
53
-
54
- DEPENDENCIES
55
- bundler (~> 2.0)
56
- fulfil!
57
- minitest (~> 5.0)
58
- minitest-reporters (~> 1.3)
59
- oauth2 (~> 1.4)
60
- rake (~> 10.0)
61
-
62
- BUNDLED WITH
63
- 2.1.4
@@ -1,54 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # frozen_string_literal: true
4
-
5
- require 'bundler'
6
- Bundler.setup(:default, :development)
7
-
8
- require 'oauth2'
9
- require 'fulfil'
10
-
11
- def get_token
12
- client_id = ENV.fetch('CLIENT_ID')
13
- client_secret = ENV.fetch('CLIENT_SECRET')
14
- subdomain = ENV.fetch('SUBDOMAIN')
15
-
16
- base_url = "https://#{subdomain}.fulfil.io" # "oauth/authorize"
17
-
18
- client = OAuth2::Client.new(client_id, client_secret, site: base_url)
19
- authorize_url = client.auth_code.authorize_url(
20
- redirect_uri: 'urn:ietf:wg:oauth:2.0:oob',
21
- scope: ['sale.channel:read'].join(','),
22
- access_type: 'offline_access'
23
- )
24
-
25
- output 'Open this URL:'
26
- system %x[echo "#{authorize_url.to_s}" | pbcopy]
27
- output authorize_url.to_s
28
-
29
- output 'Copy the generated token. Paste it here:'
30
-
31
- auth_token = gets.chomp
32
- output ''
33
- token = client.auth_code.get_token(auth_token)
34
-
35
- output 'Results:'
36
- pp token.to_hash
37
- output ''
38
-
39
- output 'Offline access token:'
40
- output token.to_hash.dig('offline_access_token')
41
- end
42
-
43
- def output(text, lines: 2)
44
- puts text
45
- puts "\n" * lines
46
- end
47
-
48
- def fulfil
49
- @fulfil ||= Fulfil::Client.new(
50
- subdomain: ENV.fetch('SUBDOMAIN'), token: ENV.fetch('TOKEN')
51
- )
52
- end
53
-
54
- get_token
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'fulfil'
5
-
6
- def fulfil
7
- @fulfil ||= Fulfil::Client.new(
8
- subdomain: ENV.fetch('SUBDOMAIN'), token: ENV.fetch('TOKEN')
9
- )
10
- end
11
-
12
- require 'irb'
13
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
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
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- lib = File.expand_path('lib', __dir__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
-
6
- require 'fulfil/version'
7
-
8
- Gem::Specification.new do |spec|
9
- spec.name = 'fulfil-io'
10
- spec.version = Fulfil::VERSION
11
- spec.authors = ['Chris Moore', 'Kat Fairbanks']
12
- spec.email = ['chris@knowndecimal.com']
13
-
14
- spec.summary = 'Interact with the Fulfil.io API'
15
- spec.homepage = 'https://github.com/knowndecimal/fulfil'
16
- spec.license = 'MIT'
17
-
18
- # Specify which files should be added to the gem when it is released.
19
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
- end
23
- spec.bindir = 'exe'
24
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
- spec.require_paths = ['lib']
26
-
27
- spec.add_dependency 'http'
28
-
29
- spec.add_development_dependency 'bundler', '~> 2.0'
30
- spec.add_development_dependency 'minitest', '~> 5.0'
31
- spec.add_development_dependency 'minitest-ci', '~> 3.4' if ENV['CI']
32
- spec.add_development_dependency 'minitest-reporters', '~> 1.3'
33
- spec.add_development_dependency 'oauth2', '~> 1.4'
34
- spec.add_development_dependency 'rake', '~> 10.0'
35
- end