action_network_rest 0.3.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c7052276bcde7acbbc808912711dd160a2ec75b13905dac5cd11d25555deadd
4
- data.tar.gz: acc6e54314b4671d2969fb91065185f249c073d6371999648d0016bcef868383
3
+ metadata.gz: a5ac436fdf54dc3a69ce38d4a38cb2f3b40db35083d20a5817db63e4546da610
4
+ data.tar.gz: a61e130172cf21c309000c632b6b57230c5d88fb18213c0c3c5961cc697e74de
5
5
  SHA512:
6
- metadata.gz: 8065e41e4a565188ad1a2b6c24bb67c2858d4ea9d793b03082c4fd2cc0764ceba51f69df7481fa3e8ba6a961217cd3e769caa6c88fbcd90c286bbc9fdf5fef30
7
- data.tar.gz: c4644fd81aba749b33a2871b4f776e182464c25f3be8f754d8d9209666aa98ea19ca1385d4fe977407a0e5e9ab0749224ee5211e2355891fba22d725e9635be2
6
+ metadata.gz: 3a5bd5ea4d0f915429a85f7c01380642c0a390bf2d011cfa507b01f094572deab777184b2d11e58ba7cc118253cd9e042e0c005936e9255cfb7fade3bbe6019b
7
+ data.tar.gz: 1f73b9a22ca1cc3328331435cdcdcc25dfffe8d1dc85e053dd0a79df14f36343374dfc4daeac812c3949bb6c2f10998487ada99df81d16e349fb39cb2f6a6c98
@@ -0,0 +1,2 @@
1
+ # API key used on example.rb, you don't need to define this in the gem including code
2
+ API_KEY=xyz
data/.gitignore CHANGED
@@ -11,7 +11,7 @@
11
11
  /tmp/
12
12
 
13
13
  # Used by dotenv library to load environment variables.
14
- # .env
14
+ .env
15
15
 
16
16
  # Ignore Byebug command history file.
17
17
  .byebug_history
@@ -0,0 +1,26 @@
1
+ AllCops:
2
+ DisabledByDefault: true
3
+
4
+ Security:
5
+ Enabled: true
6
+
7
+ Bundler/DuplicatedGem:
8
+ Enabled: true
9
+ Bundler/InsecureProtocolSource:
10
+ Enabled: true
11
+ Layout/IndentationStyle:
12
+ Enabled: true
13
+ Layout/SpaceInsideRangeLiteral:
14
+ Enabled: true
15
+ Lint:
16
+ Enabled: true
17
+ Lint/RaiseException:
18
+ Enabled: true
19
+ Naming/AsciiIdentifiers:
20
+ Enabled: true
21
+ Naming/ClassAndModuleCamelCase:
22
+ Enabled: true
23
+ Naming/ConstantName:
24
+ Enabled: true
25
+ Naming/FileName:
26
+ Enabled: true
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.6
4
+ cache: bundler
5
+ before_install:
6
+ - gem install bundler
7
+ script:
8
+ - bundle exec rspec
9
+ - bundle exec rubocop
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # ActionNetworkRest
2
2
 
3
- Ruby client for interacting with the [ActionNetwork REST API](https://actionnetwork.org/docs/)
3
+ Ruby client for interacting with the [ActionNetwork REST API](https://actionnetwork.org/docs/) from the engineering team at [ControlShift](https://www.controlshiftlabs.com/).
4
+
5
+ [![Build Status](https://travis-ci.org/controlshift/action-network-rest.svg?branch=master)](https://travis-ci.org/controlshift/action-network-rest)
4
6
 
5
7
  ## Installation
6
8
 
@@ -37,6 +39,11 @@ person_id = person.action_network_id
37
39
  person = client.people.get(person_id)
38
40
  puts person.email_addresses
39
41
 
42
+ # Retrieve a Person's data by their email address
43
+ person = client.people.find_by_email(person_email
44
+ person_id = person.action_network_id
45
+ puts person.email_addresses
46
+
40
47
  # Unsubscribe a Person
41
48
  client.people.unsubscribe(person_id)
42
49
 
@@ -88,6 +95,8 @@ After checking out the repo, run `bundle install` to install dependencies. Then,
88
95
 
89
96
  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).
90
97
 
98
+ To run a REPL with an initialized client object you'll need to create your own `.env` file based off `.env.sample` and then run `bundle exec ruby example.rb`.
99
+
91
100
  ## Contributing
92
101
 
93
102
  Bug reports and pull requests are welcome on GitHub at https://github.com/controlshift/action-network-rest. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
@@ -23,7 +23,10 @@ Gem::Specification.new do |spec|
23
23
  spec.add_runtime_dependency "vertebrae", "~> 0.6.0"
24
24
 
25
25
  spec.add_development_dependency "bundler", "~> 2.1"
26
+ spec.add_development_dependency "byebug", "~> 11.1"
27
+ spec.add_development_dependency "dotenv", "~> 2.7"
26
28
  spec.add_development_dependency "rake", "~> 13.0"
27
29
  spec.add_development_dependency "rspec", "~> 3.0"
28
30
  spec.add_development_dependency 'webmock', '~> 3.8.3'
31
+ spec.add_development_dependency 'rubocop'
29
32
  end
@@ -0,0 +1,13 @@
1
+ require_relative 'lib/action_network_rest'
2
+ require 'dotenv'
3
+ require 'byebug'
4
+
5
+ Dotenv.load('.env')
6
+ raise 'Must set API_KEY environmental variable. See .env.sample for details' if ENV['API_KEY'].nil?
7
+
8
+ client = ActionNetworkRest.new(api_key: ENV['API_KEY']) # rubocop:disable Lint/UselessAssignment
9
+
10
+ puts "Ready to call Action Network API using 'client' object"
11
+ byebug # rubocop:disable Lint/Debugger
12
+
13
+ puts "Bye!"
@@ -11,19 +11,15 @@ module ActionNetworkRest
11
11
  CGI.escape(string.to_s)
12
12
  end
13
13
 
14
- def object_from_response(response)
15
- obj = response.body
16
-
17
- # The response we get from Action Network may contain an "identifiers" block that looks something like:
18
- #
14
+ def object_with_action_network_id(obj)
15
+ # Takes an object which may contain an `identifiers` key, which may contain an action_network identifier
16
+ # If so, we pull out the action_network identifier and stick it in a top-level key "action_network_id",
17
+ # for the convenience of callers using the returned object.
19
18
  # "identifiers": [
20
19
  # "action_network:d6bdf50e-c3a4-4981-a948-3d8c086066d7",
21
20
  # "some_external_system:1",
22
21
  # "another_external_system:57"
23
22
  # ]
24
- #
25
- # If so, we pull out the action_network identifier and stick it in a top-level key "action_network_id",
26
- # for the convenience of callers using the returned object.
27
23
  identifiers = obj[:identifiers] || []
28
24
  qualified_actionnetwork_id = identifiers.find do |id|
29
25
  id.split(':').first == 'action_network'
@@ -35,6 +31,11 @@ module ActionNetworkRest
35
31
  obj
36
32
  end
37
33
 
34
+ def object_from_response(response)
35
+ obj = response.body
36
+ object_with_action_network_id(obj)
37
+ end
38
+
38
39
  def action_network_url(path)
39
40
  client.connection.configuration.endpoint + path
40
41
  end
@@ -4,7 +4,7 @@ module ActionNetworkRest
4
4
 
5
5
  def initialize(options={}, &block)
6
6
  self.api_key = options[:api_key]
7
- super(options={}, &block)
7
+ super(options, &block)
8
8
  end
9
9
 
10
10
  def default_options
@@ -19,5 +19,26 @@ module ActionNetworkRest
19
19
  response = client.put_request "#{base_path}#{url_escape(id)}", request_body
20
20
  object_from_response(response)
21
21
  end
22
+
23
+ def find_by_email(email)
24
+ # This works for parsing exactly 1 person's info out of the response.
25
+ # The response we get from Action Network is expected to have
26
+ #
27
+ # "_embedded": {
28
+ # "osdi:people": [{
29
+ # "identifiers": [
30
+ # "action_network:c947bcd0-929e-11e3-a2e9-12313d316c29"
31
+ # ....
32
+ # ]
33
+ # }]
34
+ # }
35
+ #
36
+ url_encoded_filter_string = url_escape("email_address eq '#{email}'")
37
+ response = client.get_request "#{base_path}?filter=#{url_encoded_filter_string}"
38
+ person_object = response.body[:_embedded]['osdi:people'].first
39
+ if person_object.present?
40
+ object_with_action_network_id(person_object)
41
+ end
42
+ end
22
43
  end
23
44
  end
@@ -1,3 +1,3 @@
1
1
  module ActionNetworkRest
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_network_rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
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-04-29 00:00:00.000000000 Z
11
+ date: 2020-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: vertebrae
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '11.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '11.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: dotenv
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.7'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: rake
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +108,20 @@ dependencies:
80
108
  - - "~>"
81
109
  - !ruby/object:Gem::Version
82
110
  version: 3.8.3
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
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'
83
125
  description:
84
126
  email:
85
127
  - grey@controlshiftlabs.com
@@ -87,9 +129,12 @@ executables: []
87
129
  extensions: []
88
130
  extra_rdoc_files: []
89
131
  files:
132
+ - ".env.sample"
90
133
  - ".gitignore"
134
+ - ".rubocop.yml"
91
135
  - ".ruby-gemset"
92
136
  - ".ruby-version"
137
+ - ".travis.yml"
93
138
  - CODE_OF_CONDUCT.md
94
139
  - Gemfile
95
140
  - LICENSE
@@ -99,6 +144,7 @@ files:
99
144
  - bin/console
100
145
  - bin/rake
101
146
  - bin/rspec
147
+ - example.rb
102
148
  - lib/action_network_rest.rb
103
149
  - lib/action_network_rest/base.rb
104
150
  - lib/action_network_rest/client.rb
@@ -128,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
174
  - !ruby/object:Gem::Version
129
175
  version: '0'
130
176
  requirements: []
131
- rubygems_version: 3.1.2
177
+ rubygems_version: 3.0.3
132
178
  signing_key:
133
179
  specification_version: 4
134
180
  summary: Ruby client for interacting with the ActionNetwork REST API