fulfil-io 0.1.0 → 0.2.0

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: d19d908e32866d5bb5f96696cc90f59724e7654374c34d49f49e376a117d9c29
4
+ data.tar.gz: ba380e30001c2409f404a36ea6335a8762ec993b45b431c08c5b5d703172e550
5
5
  SHA512:
6
- metadata.gz: 577b1cb9f71d27cfa533fd8dce8db1e6491f0c9ac8e798b412c6f454ac64879b6ca9e9de86d87670ece787047295d74e533f15d5de343fc0820fd9dfc6aa3a62
7
- data.tar.gz: 579ccb9a08afe4c30c2ad9d8627c8f941b6b0f03da5a6397c13f3264061aae227777d7c0929c36dd08b56e53839802a8d3dbbaa2dc73ec65278cc59613501c5c
6
+ metadata.gz: 7d60b09fcfb88fcf29e160d1c6acef304ce57134dff910f881166ddb5dac88c83a697e65132ca59778ec47695f5f346269154ac76b120d201781221128bf47a8
7
+ data.tar.gz: 7db725e451c38016cd63fda0ccbe46b9e1257236f660c021f3f649c9ca4dad3a80fe652143e526e79f29e0ea6f60453d9e50f43883292490653a64d4d8661760
@@ -1,3 +1,17 @@
1
+ ## 0.2.0
2
+
3
+ - Make token optional and allow specifying headers at least for enabling authentication via 'X-API-KEY' header
4
+ , because initially implemented in 0.1.0 bearer auth isn't working.
5
+
6
+ - Fix Query `build_search_term` and `build_exclude_term` to be compatible with Ruby < 2.4, analyzing value for 'Fixnum
7
+ ' class.
8
+
9
+ - Fix the gem's name in gemspec to 'fulfil-io', as registered at RubyGems.
10
+
11
+ - Remove Rake version constraint from gemspec.
12
+
13
+ - Add Gemfile.lock to .gitignore and remove it from git-tree - it shouldn't be stored in git for a gem.
14
+
1
15
  ## 0.1.0
2
16
 
3
17
  * 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:
32
+
33
+ When FULFIL_TOKEN is present, the FULFIL_API_KEY will be ignored. So, if oauth doesn't work, returning an Unauthorized error, to use the 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,
@@ -1,15 +1,19 @@
1
- # frozen_string_literal: true
2
-
3
1
  require 'http'
4
2
  require 'logger'
5
3
  require 'fulfil/response_parser'
6
4
 
7
5
  module Fulfil
6
+ SUBDOMAIN = ENV['FULFIL_SUBDOMAIN']
7
+ API_KEY = ENV['FULFIL_API_KEY']
8
+ OAUTH_TOKEN = ENV['FULFIL_TOKEN']
9
+
8
10
  class Client
9
- def initialize(subdomain:, token:, debug: false)
11
+ def initialize(subdomain: SUBDOMAIN, token: OAUTH_TOKEN, headers: { 'X-API-KEY' => API_KEY }, debug: false)
10
12
  @subdomain = subdomain
11
13
  @token = token
12
14
  @debug = debug
15
+ @headers = headers
16
+ @headers.delete('X-API-KEY') if @token
13
17
  end
14
18
 
15
19
  def find(model:, ids: [], id: nil, fields: %w[id rec_name])
@@ -38,9 +42,7 @@ module Fulfil
38
42
  parse(results: results)
39
43
  end
40
44
 
41
- def search(
42
- model:, domain:, offset: nil, limit: 100, sort: nil, fields: %w[id]
43
- )
45
+ def search(model:, domain:, offset: nil, limit: 100, sort: nil, fields: %w[id])
44
46
  uri = URI("#{model_url(model: model)}/search_read")
45
47
  body = [domain, offset, limit, sort, fields]
46
48
 
@@ -48,13 +50,6 @@ module Fulfil
48
50
  parse(results: results)
49
51
  end
50
52
 
51
- def post(model:, body: {})
52
- uri = URI(model_url(model: model))
53
-
54
- results = request(verb: :post, endpoint: uri, json: body)
55
- parse(results: results)
56
- end
57
-
58
53
  private
59
54
 
60
55
  def parse(result: nil, results: [])
@@ -72,29 +67,28 @@ module Fulfil
72
67
  def request(verb: :get, endpoint:, **args)
73
68
  response = client.request(verb, endpoint, args)
74
69
 
75
- if response.status.ok? || response.status.created?
70
+ if response.status.ok?
76
71
  response.parse
77
72
  elsif response.code == 401
78
- raise StandardError, 'Not authorized'
73
+ raise StandardError, "Not authorized"
79
74
  else
80
- puts response.body.to_s
81
- raise Error, 'Error encountered while processing response:'
75
+ pp response.parse
76
+ raise StandardError, "Invalid response"
82
77
  end
83
- rescue HTTP::Error => e
84
- puts e
85
- raise Error, 'Unhandled HTTP error encountered'
86
- rescue HTTP::ConnectionError => e
78
+ rescue HTTP::ConnectionError => ex
87
79
  puts "Couldn't connect"
88
80
  raise Error, "Can't connect to #{base_url}"
89
- rescue HTTP::ResponseError => e
90
- raise Error, "Can't process response: #{e}"
91
- []
81
+ rescue HTTP::ResponseError => ex
82
+ raise Error, "Can't process response: #{ex}"
92
83
  end
93
84
 
94
85
  def client
95
- @client ||=
96
- HTTP.persistent(base_url).auth("Bearer #{@token}")
97
- .use(logging: @debug ? { logger: Logger.new(STDOUT) } : {})
86
+ return @client if defined?(@client)
87
+
88
+ @client = HTTP.persistent(base_url).use(logging: @debug ? { logger: Logger.new(STDOUT) } : {})
89
+ @client = @client.auth("Bearer #{@token}") if @token
90
+ @client = @client.headers(@headers)
91
+ @client
98
92
  end
99
93
  end
100
94
  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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Fulfil
2
- VERSION = "0.1.0"
4
+ VERSION = '0.2.0'
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.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Moore
8
8
  - Kat Fairbanks
9
9
  autorequire:
10
- bindir: exe
10
+ bindir: bin
11
11
  cert_chain: []
12
- date: 2020-06-25 00:00:00.000000000 Z
12
+ date: 2020-09-10 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'
97
+ version: '0'
98
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
@@ -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
  - - ">="
@@ -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