mobilize-america-client 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/README.md +20 -2
- data/VERSION +1 -1
- data/example.rb +14 -0
- data/lib/mobilize_america_client.rb +2 -2
- data/lib/mobilize_america_client/client.rb +7 -2
- data/lib/mobilize_america_client/client/events.rb +4 -0
- data/lib/mobilize_america_client/request.rb +5 -0
- data/mobilize-america-client.gemspec +12 -4
- data/spec/client/client_spec.rb +9 -0
- data/spec/client/events_spec.rb +20 -6
- metadata +33 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a0362285775791640e9e587d2ea5875981615bf134364f5438d2ce878472eb8
|
4
|
+
data.tar.gz: 1497262d8a8bacde3d68082e4766b883b677480960fe33744994a87853ceb2cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d455bb7eda9dddf648794b53f48cdc4ccf7630492b0cc4709c17844c8d4978471df75e57743e91c320fedff7621132997030e2e7d48874c0550a2bc8b8c9a698
|
7
|
+
data.tar.gz: e7f5a5ef755ab7b485e9ac8a89a97fb5ea663a507fef97ed5a3b3f62d5c5a25259f5eb77286b5472be0aca2517ba225aef626b335e95c40f726d98b20c946daa
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -20,11 +20,29 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
$ gem install mobilize-america-client
|
22
22
|
|
23
|
+
## Configuration
|
24
|
+
|
25
|
+
By default, the client accesses the public production instance without authentication.
|
26
|
+
|
27
|
+
`client = MobilizeAmericaClient::Client.new`
|
28
|
+
|
29
|
+
It is also possible to provide an API key to the client to make authenticated requests, or to specify
|
30
|
+
other endpoints.
|
31
|
+
|
32
|
+
`client = MobilizeAmericaClient::Client.new(api_key: 'abc123', api_domain: 'staging-api.mobilize.us')`
|
33
|
+
|
34
|
+
|
23
35
|
## Usage
|
24
36
|
|
25
|
-
|
37
|
+
Retrieve a list of organizations
|
38
|
+
`client.organizations(page: 2, per_page: 50)`
|
39
|
+
|
40
|
+
|
41
|
+
Retrieve a list of an organization's events
|
42
|
+
`client.organization_events(organization_id: 123)`
|
26
43
|
|
27
|
-
|
44
|
+
Retrieve a specific event
|
45
|
+
`client.organization_event(organization_id: 123, event_id: 123)`
|
28
46
|
|
29
47
|
|
30
48
|
## Development
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.5
|
data/example.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'mobilize_america_client'
|
4
|
+
require 'dotenv'
|
5
|
+
require 'byebug'
|
6
|
+
|
7
|
+
Dotenv.load('.env')
|
8
|
+
|
9
|
+
client = MobilizeAmericaClient::Client.new(api_key: ENV['API_KEY'], api_domain: ENV['API_DOMAIN']) # rubocop:disable Lint/UselessAssignment
|
10
|
+
|
11
|
+
puts "Ready to call Mobilize America using 'client' object"
|
12
|
+
byebug # rubocop:disable Lint/Debugger
|
13
|
+
|
14
|
+
puts "Bye!"
|
@@ -6,9 +6,14 @@ require 'mobilize_america_client/request'
|
|
6
6
|
module MobilizeAmericaClient
|
7
7
|
class Client
|
8
8
|
attr_reader :connection
|
9
|
+
attr_accessor :api_key
|
9
10
|
|
10
|
-
def initialize
|
11
|
-
|
11
|
+
def initialize(options = {})
|
12
|
+
self.api_key = options[:api_key]
|
13
|
+
|
14
|
+
api_domain = options[:api_domain] || API_DOMAIN
|
15
|
+
|
16
|
+
@connection = Faraday.new(url: "https://#{api_domain}")
|
12
17
|
end
|
13
18
|
|
14
19
|
include MobilizeAmericaClient::Request
|
@@ -36,5 +36,9 @@ module MobilizeAmericaClient
|
|
36
36
|
get(path: "/organizations/#{esc(organization_id)}/events", params: params)
|
37
37
|
end
|
38
38
|
end
|
39
|
+
|
40
|
+
def organization_event(organization_id:, event_id:)
|
41
|
+
get(path: "/organizations/#{esc(organization_id)}/events/#{esc(event_id)}")
|
42
|
+
end
|
39
43
|
end
|
40
44
|
end
|
@@ -20,6 +20,11 @@ module MobilizeAmericaClient
|
|
20
20
|
req.path = "#{API_BASE_PATH}#{path}"
|
21
21
|
req.params = params
|
22
22
|
req.headers['Content-Type'] = 'application/json'
|
23
|
+
|
24
|
+
unless api_key.nil?
|
25
|
+
req.headers['Authorization'] = "Bearer #{api_key}"
|
26
|
+
end
|
27
|
+
|
23
28
|
req.body = ::JSON.generate(body) unless body.empty?
|
24
29
|
end
|
25
30
|
|
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: mobilize-america-client 0.3.
|
5
|
+
# stub: mobilize-america-client 0.3.5 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "mobilize-america-client".freeze
|
9
|
-
s.version = "0.3.
|
9
|
+
s.version = "0.3.5"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
13
13
|
s.authors = ["Grey Moore".freeze]
|
14
|
-
s.date = "2020-10-
|
14
|
+
s.date = "2020-10-14"
|
15
15
|
s.email = "grey@controlshiftlabs.com".freeze
|
16
16
|
s.executables = ["console".freeze, "setup".freeze]
|
17
17
|
s.extra_rdoc_files = [
|
@@ -32,12 +32,14 @@ Gem::Specification.new do |s|
|
|
32
32
|
"VERSION",
|
33
33
|
"bin/console",
|
34
34
|
"bin/setup",
|
35
|
+
"example.rb",
|
35
36
|
"lib/mobilize_america_client.rb",
|
36
37
|
"lib/mobilize_america_client/client.rb",
|
37
38
|
"lib/mobilize_america_client/client/events.rb",
|
38
39
|
"lib/mobilize_america_client/client/organizations.rb",
|
39
40
|
"lib/mobilize_america_client/request.rb",
|
40
41
|
"mobilize-america-client.gemspec",
|
42
|
+
"spec/client/client_spec.rb",
|
41
43
|
"spec/client/events_spec.rb",
|
42
44
|
"spec/client/organizations_spec.rb",
|
43
45
|
"spec/fixtures/organizations.json",
|
@@ -45,7 +47,7 @@ Gem::Specification.new do |s|
|
|
45
47
|
]
|
46
48
|
s.homepage = "http://github.com/controlshift/mobilize_america_client".freeze
|
47
49
|
s.licenses = ["MIT".freeze]
|
48
|
-
s.rubygems_version = "3.0.
|
50
|
+
s.rubygems_version = "3.0.8".freeze
|
49
51
|
s.summary = "Client gem for the MobilizeAmerica API".freeze
|
50
52
|
|
51
53
|
if s.respond_to? :specification_version then
|
@@ -58,6 +60,8 @@ Gem::Specification.new do |s|
|
|
58
60
|
s.add_development_dependency(%q<rake>.freeze, [">= 0"])
|
59
61
|
s.add_development_dependency(%q<webmock>.freeze, [">= 0"])
|
60
62
|
s.add_development_dependency(%q<rubocop>.freeze, [">= 0"])
|
63
|
+
s.add_development_dependency(%q<dotenv>.freeze, [">= 0"])
|
64
|
+
s.add_development_dependency(%q<byebug>.freeze, [">= 0"])
|
61
65
|
else
|
62
66
|
s.add_dependency(%q<faraday>.freeze, ["> 0.15"])
|
63
67
|
s.add_dependency(%q<rspec>.freeze, [">= 0"])
|
@@ -65,6 +69,8 @@ Gem::Specification.new do |s|
|
|
65
69
|
s.add_dependency(%q<rake>.freeze, [">= 0"])
|
66
70
|
s.add_dependency(%q<webmock>.freeze, [">= 0"])
|
67
71
|
s.add_dependency(%q<rubocop>.freeze, [">= 0"])
|
72
|
+
s.add_dependency(%q<dotenv>.freeze, [">= 0"])
|
73
|
+
s.add_dependency(%q<byebug>.freeze, [">= 0"])
|
68
74
|
end
|
69
75
|
else
|
70
76
|
s.add_dependency(%q<faraday>.freeze, ["> 0.15"])
|
@@ -73,6 +79,8 @@ Gem::Specification.new do |s|
|
|
73
79
|
s.add_dependency(%q<rake>.freeze, [">= 0"])
|
74
80
|
s.add_dependency(%q<webmock>.freeze, [">= 0"])
|
75
81
|
s.add_dependency(%q<rubocop>.freeze, [">= 0"])
|
82
|
+
s.add_dependency(%q<dotenv>.freeze, [">= 0"])
|
83
|
+
s.add_dependency(%q<byebug>.freeze, [">= 0"])
|
76
84
|
end
|
77
85
|
end
|
78
86
|
|
data/spec/client/events_spec.rb
CHANGED
@@ -14,13 +14,13 @@ RSpec.describe MobilizeAmericaClient::Client::Events do
|
|
14
14
|
|
15
15
|
it 'should call the endpoint and return JSON' do
|
16
16
|
stub_request(:get, events_url).with(headers: standard_headers).to_return(body: response.to_json)
|
17
|
-
expect(subject.organization_events(organization_id: org_id)).to eq
|
17
|
+
expect(subject.organization_events(organization_id: org_id)).to eq(response)
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'should escape the organization ID' do
|
21
21
|
expected_url = "#{base_url}/organizations/foo%2Fbar/events"
|
22
22
|
stub_request(:get, expected_url).with(headers: standard_headers).to_return(body: response.to_json)
|
23
|
-
expect(subject.organization_events(organization_id: 'foo/bar')).to eq
|
23
|
+
expect(subject.organization_events(organization_id: 'foo/bar')).to eq(response)
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'should support a timeslot_start parameter' do
|
@@ -45,7 +45,7 @@ RSpec.describe MobilizeAmericaClient::Client::Events do
|
|
45
45
|
stub_request(:get, events_url)
|
46
46
|
.with(headers: standard_headers, query: {updated_since: updated_since.to_i})
|
47
47
|
.to_return(body: response.to_json)
|
48
|
-
expect(subject.organization_events(organization_id: org_id, updated_since: updated_since)).to eq
|
48
|
+
expect(subject.organization_events(organization_id: org_id, updated_since: updated_since)).to eq(response)
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'should support a zipcode parameter' do
|
@@ -53,21 +53,35 @@ RSpec.describe MobilizeAmericaClient::Client::Events do
|
|
53
53
|
stub_request(:get, events_url)
|
54
54
|
.with(headers: standard_headers, query: {zipcode: zipcode})
|
55
55
|
.to_return(body: response.to_json)
|
56
|
-
expect(subject.organization_events(organization_id: org_id, zipcode: zipcode)).to eq
|
56
|
+
expect(subject.organization_events(organization_id: org_id, zipcode: zipcode)).to eq(response)
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'should support a max_dist parameter to go with zipcode' do
|
60
60
|
stub_request(:get, events_url)
|
61
61
|
.with(headers: standard_headers, query: {zipcode: '23456', max_dist: 100})
|
62
62
|
.to_return(body: response.to_json)
|
63
|
-
expect(subject.organization_events(organization_id: org_id, zipcode: '23456', max_distance_miles: 100)).to eq
|
63
|
+
expect(subject.organization_events(organization_id: org_id, zipcode: '23456', max_distance_miles: 100)).to eq(response)
|
64
64
|
end
|
65
65
|
|
66
66
|
it 'should support pagination parameters' do
|
67
67
|
stub_request(:get, events_url)
|
68
68
|
.with(headers: standard_headers, query: {page: 2, per_page: 100})
|
69
69
|
.to_return(body: response.to_json)
|
70
|
-
expect(subject.organization_events(organization_id: org_id, page: 2, per_page: 100)).to eq
|
70
|
+
expect(subject.organization_events(organization_id: org_id, page: 2, per_page: 100)).to eq(response)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#organization_event' do
|
75
|
+
let(:org_id) { 123 }
|
76
|
+
let(:event_id) { 456 }
|
77
|
+
let(:events_url) { "#{base_url}/organizations/#{org_id}/events/#{event_id}" }
|
78
|
+
let(:response) { '{"hello": "world"}' }
|
79
|
+
|
80
|
+
it 'should support pagination parameters' do
|
81
|
+
stub_request(:get, events_url)
|
82
|
+
.with(headers: standard_headers)
|
83
|
+
.to_return(body: response.to_json)
|
84
|
+
expect(subject.organization_event(organization_id: org_id, event_id: event_id)).to eq(response)
|
71
85
|
end
|
72
86
|
end
|
73
87
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mobilize-america-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Grey Moore
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -94,6 +94,34 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: dotenv
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
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: byebug
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
97
125
|
description:
|
98
126
|
email: grey@controlshiftlabs.com
|
99
127
|
executables:
|
@@ -117,12 +145,14 @@ files:
|
|
117
145
|
- VERSION
|
118
146
|
- bin/console
|
119
147
|
- bin/setup
|
148
|
+
- example.rb
|
120
149
|
- lib/mobilize_america_client.rb
|
121
150
|
- lib/mobilize_america_client/client.rb
|
122
151
|
- lib/mobilize_america_client/client/events.rb
|
123
152
|
- lib/mobilize_america_client/client/organizations.rb
|
124
153
|
- lib/mobilize_america_client/request.rb
|
125
154
|
- mobilize-america-client.gemspec
|
155
|
+
- spec/client/client_spec.rb
|
126
156
|
- spec/client/events_spec.rb
|
127
157
|
- spec/client/organizations_spec.rb
|
128
158
|
- spec/fixtures/organizations.json
|
@@ -146,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
176
|
- !ruby/object:Gem::Version
|
147
177
|
version: '0'
|
148
178
|
requirements: []
|
149
|
-
rubygems_version: 3.0.
|
179
|
+
rubygems_version: 3.0.8
|
150
180
|
signing_key:
|
151
181
|
specification_version: 4
|
152
182
|
summary: Client gem for the MobilizeAmerica API
|