northpasser 0.1.2 → 2.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 +4 -4
- data/.gitignore +1 -1
- data/Gemfile.lock +1 -3
- data/README.md +5 -9
- data/lib/northpasser.rb +3 -1
- data/lib/northpasser/path_builder.rb +19 -2
- data/lib/northpasser/request.rb +1 -1
- data/lib/northpasser/v1_constants.rb +31 -0
- data/lib/northpasser/v2_constants.rb +14 -0
- data/lib/northpasser/version.rb +1 -1
- data/lib/northpasser/versionless_constants.rb +26 -0
- data/northpasser.gemspec +1 -2
- metadata +7 -19
- data/lib/northpasser/constants.rb +0 -52
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0db00a9394417615c31a808555aecaf053a59e82
|
4
|
+
data.tar.gz: 3398492a360bf5ce2d9088abad5fd32c5c60f62e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b71a66c56fbea1b14eae44c3b70f3bcbccacd0ebf18fd0753bd257c2ad37c3d29941d19069313b8233f7e37cb34bad17c6a0416f7a0e51d8acbd6331b3234f7
|
7
|
+
data.tar.gz: e65295a5c4cc88365088c9064223bd32d74d325c65eca842499205fcfdd38bb4216f21eed88adf813cfd27d037d111da9d433c3f4836c711fde54d42b7cd5b15
|
data/.gitignore
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
.env
|
2
|
-
|
2
|
+
coverage/*
|
data/Gemfile.lock
CHANGED
@@ -41,7 +41,6 @@ GEM
|
|
41
41
|
json (>= 1.8, < 3)
|
42
42
|
simplecov-html (~> 0.10.0)
|
43
43
|
simplecov-html (0.10.2)
|
44
|
-
vcr (3.0.3)
|
45
44
|
webmock (2.3.2)
|
46
45
|
addressable (>= 2.3.6)
|
47
46
|
crack (>= 0.3.2)
|
@@ -58,8 +57,7 @@ DEPENDENCIES
|
|
58
57
|
rake (~> 10.0)
|
59
58
|
rspec (~> 3.0)
|
60
59
|
simplecov
|
61
|
-
vcr (~> 3.0)
|
62
60
|
webmock (~> 2.1)
|
63
61
|
|
64
62
|
BUNDLED WITH
|
65
|
-
1.
|
63
|
+
1.16.1
|
data/README.md
CHANGED
@@ -184,22 +184,18 @@ use `bin/console` for an interactive prompt that allows you to experiment with
|
|
184
184
|
the gem and real API responses.
|
185
185
|
|
186
186
|
Use `rake spec` to run the tests. The tests don't make external requests but
|
187
|
-
rather use
|
188
|
-
|
189
|
-
you
|
187
|
+
rather use WebMock to mock Northpass API calls. This allows you to run and develop
|
188
|
+
directly against the Northpass API without needing a valid Northpass API token.
|
189
|
+
If you want to play with the tests and get real API responses (perhaps to extend the suite or for a new feature)
|
190
|
+
then you'll need to have an API token in the env as described above.
|
190
191
|
|
191
192
|
The current test suite is far from exhaustive and could do with some
|
192
193
|
love.
|
193
194
|
|
194
|
-
**NB: If you have implemented a feature that requires a new cassette, make sure
|
195
|
-
you change the uri referenced by the cassette you added to remove the API token
|
196
|
-
if you have updated the environment to use your token. Otherwise your API token
|
197
|
-
will be in publically visible from the code in this repo.**
|
198
|
-
|
199
195
|
## Contributing
|
200
196
|
|
201
197
|
Bug reports and pull requests are entirely welcome on GitHub at
|
202
|
-
https://github.com/
|
198
|
+
https://github.com/mrkhutter/northpasser.
|
203
199
|
|
204
200
|
|
205
201
|
## License
|
data/lib/northpasser.rb
CHANGED
@@ -2,7 +2,7 @@ module Northpasser
|
|
2
2
|
module PathBuilder
|
3
3
|
def self.included(_)
|
4
4
|
class_exec do
|
5
|
-
attr_accessor :path
|
5
|
+
attr_accessor :path, :version_url
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
@@ -26,6 +26,7 @@ module Northpasser
|
|
26
26
|
if known_action?(name)
|
27
27
|
execute_request(ACTIONS[name], args.first)
|
28
28
|
elsif known_resource?(name)
|
29
|
+
build_version_url(name)
|
29
30
|
build_path(name, args.first)
|
30
31
|
elsif known_exception?(name)
|
31
32
|
build_path(EXCEPTIONS[name][:path], nil)
|
@@ -63,7 +64,15 @@ module Northpasser
|
|
63
64
|
end
|
64
65
|
|
65
66
|
def known_resource?(name)
|
66
|
-
|
67
|
+
known_v1_resource?(name) || known_v2_resource?(name)
|
68
|
+
end
|
69
|
+
|
70
|
+
def known_v1_resource?(name)
|
71
|
+
V1_RESOURCES.include?(name)
|
72
|
+
end
|
73
|
+
|
74
|
+
def known_v2_resource?(name)
|
75
|
+
V2_RESOURCES.include?(name)
|
67
76
|
end
|
68
77
|
|
69
78
|
def known_exception?(name)
|
@@ -80,6 +89,14 @@ module Northpasser
|
|
80
89
|
req.fetch
|
81
90
|
end
|
82
91
|
|
92
|
+
def build_version_url(name)
|
93
|
+
self.version_url = V1_API_URL
|
94
|
+
if known_v2_resource?(name)
|
95
|
+
self.version_url = V2_API_URL
|
96
|
+
end
|
97
|
+
self
|
98
|
+
end
|
99
|
+
|
83
100
|
def build_path(resource, id)
|
84
101
|
self.path ||= []
|
85
102
|
self.path << resource
|
data/lib/northpasser/request.rb
CHANGED
@@ -43,7 +43,7 @@ module Northpasser
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def construct_uri(northpass)
|
46
|
-
base_url = V1_API_URL
|
46
|
+
base_url = northpass.version_url #V1_API_URL
|
47
47
|
path = northpass.path.map(&:to_s).map { |p| p.gsub('_', '-') }.join('/')
|
48
48
|
object_id = "/#{self.params.delete(:id)}" if self.params.key?(:id)
|
49
49
|
token = northpass.token
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'csv'
|
3
|
+
|
4
|
+
module Northpasser
|
5
|
+
V1_API_URL = "https://api.northpass.com/v1/".freeze
|
6
|
+
|
7
|
+
# These are the resource for the northpass v1 api and can form part of the path
|
8
|
+
V1_RESOURCES = [
|
9
|
+
:assignments,
|
10
|
+
:categories,
|
11
|
+
:coupons,
|
12
|
+
:courses,
|
13
|
+
:groups,
|
14
|
+
:learners,
|
15
|
+
:memberships,
|
16
|
+
:people,
|
17
|
+
:quizzes
|
18
|
+
].freeze
|
19
|
+
|
20
|
+
# These are the annoying edge cases in the northpass api that are don't fit
|
21
|
+
EXCEPTIONS = {
|
22
|
+
bulk_people: {
|
23
|
+
path: "bulk/people",
|
24
|
+
action: :Post
|
25
|
+
},
|
26
|
+
bulk_groups: {
|
27
|
+
path: "bulk/groups",
|
28
|
+
action: :Post
|
29
|
+
}
|
30
|
+
}.freeze
|
31
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'csv'
|
3
|
+
|
4
|
+
module Northpasser
|
5
|
+
V2_API_URL = "https://api.northpass.com/v2/".freeze
|
6
|
+
|
7
|
+
# These are the resource for the northpass v2 api and can form part of the path
|
8
|
+
V2_RESOURCES = [
|
9
|
+
:activities,
|
10
|
+
:assignment_submissions,
|
11
|
+
:events,
|
12
|
+
:people
|
13
|
+
].freeze
|
14
|
+
end
|
data/lib/northpasser/version.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'csv'
|
3
|
+
|
4
|
+
module Northpasser
|
5
|
+
|
6
|
+
# Response formats the northpass api knows about
|
7
|
+
FORMATS = {
|
8
|
+
json: {
|
9
|
+
headers: { header: 'Content-Type', content: 'application/json' },
|
10
|
+
parser: JSON
|
11
|
+
},
|
12
|
+
csv: {
|
13
|
+
headers: { header: 'Accept', content: 'text/csv' },
|
14
|
+
parser: CSV
|
15
|
+
}
|
16
|
+
}.freeze
|
17
|
+
|
18
|
+
# Action words are nice for our internal api and match the api path too
|
19
|
+
ACTIONS = {
|
20
|
+
get: :Get,
|
21
|
+
update: :Put,
|
22
|
+
delete: :Delete,
|
23
|
+
list: :Get,
|
24
|
+
create: :Post
|
25
|
+
}.freeze
|
26
|
+
end
|
data/northpasser.gemspec
CHANGED
@@ -23,7 +23,6 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "rspec", "~> 3.0"
|
24
24
|
spec.add_development_dependency "dotenv", "~> 2.1"
|
25
25
|
spec.add_development_dependency "webmock", "~> 2.1"
|
26
|
-
spec.add_development_dependency "vcr", "~> 3.0"
|
27
|
-
spec.add_development_dependency "pry"
|
28
26
|
spec.add_development_dependency "simplecov"
|
27
|
+
spec.add_development_dependency "pry"
|
29
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: northpasser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Hutter
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -81,21 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '2.1'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '3.0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '3.0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: pry
|
84
|
+
name: simplecov
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
100
86
|
requirements:
|
101
87
|
- - ">="
|
@@ -109,7 +95,7 @@ dependencies:
|
|
109
95
|
- !ruby/object:Gem::Version
|
110
96
|
version: '0'
|
111
97
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
98
|
+
name: pry
|
113
99
|
requirement: !ruby/object:Gem::Requirement
|
114
100
|
requirements:
|
115
101
|
- - ">="
|
@@ -138,10 +124,12 @@ files:
|
|
138
124
|
- bin/console
|
139
125
|
- bin/setup
|
140
126
|
- lib/northpasser.rb
|
141
|
-
- lib/northpasser/constants.rb
|
142
127
|
- lib/northpasser/path_builder.rb
|
143
128
|
- lib/northpasser/request.rb
|
129
|
+
- lib/northpasser/v1_constants.rb
|
130
|
+
- lib/northpasser/v2_constants.rb
|
144
131
|
- lib/northpasser/version.rb
|
132
|
+
- lib/northpasser/versionless_constants.rb
|
145
133
|
- northpasser.gemspec
|
146
134
|
homepage: https://github.com/mrkhutter/northpasser
|
147
135
|
licenses:
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
require 'csv'
|
3
|
-
|
4
|
-
module Northpasser
|
5
|
-
V1_API_URL = "https://api.northpass.com/v1/".freeze
|
6
|
-
|
7
|
-
# Response formats the northpass api knows about
|
8
|
-
FORMATS = {
|
9
|
-
json: {
|
10
|
-
headers: { header: 'Content-Type', content: 'application/json' },
|
11
|
-
parser: JSON
|
12
|
-
},
|
13
|
-
csv: {
|
14
|
-
headers: { header: 'Accept', content: 'text/csv' },
|
15
|
-
parser: CSV
|
16
|
-
}
|
17
|
-
}.freeze
|
18
|
-
|
19
|
-
# Action words are nice for our internal api and match the api path too
|
20
|
-
ACTIONS = {
|
21
|
-
get: :Get,
|
22
|
-
update: :Put,
|
23
|
-
delete: :Delete,
|
24
|
-
list: :Get,
|
25
|
-
create: :Post
|
26
|
-
}.freeze
|
27
|
-
|
28
|
-
# These are the resource for the northpass api and can form part of the path
|
29
|
-
RESOURCES = [
|
30
|
-
:assignments,
|
31
|
-
:categories,
|
32
|
-
:coupons,
|
33
|
-
:courses,
|
34
|
-
:groups,
|
35
|
-
:learners,
|
36
|
-
:memberships,
|
37
|
-
:people,
|
38
|
-
:quizzes
|
39
|
-
].freeze
|
40
|
-
|
41
|
-
# These are the annoying edge cases in the northpass api that are don't fit
|
42
|
-
EXCEPTIONS = {
|
43
|
-
bulk_people: {
|
44
|
-
path: "bulk/people",
|
45
|
-
action: :Post
|
46
|
-
},
|
47
|
-
bulk_groups: {
|
48
|
-
path: "bulk/groups",
|
49
|
-
action: :Post
|
50
|
-
}
|
51
|
-
}.freeze
|
52
|
-
end
|