rd_station_client 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +120 -0
- data/CHANGELOG.md +13 -0
- data/Gemfile +24 -0
- data/Gemfile.lock +137 -0
- data/LICENSE.txt +21 -0
- data/README.md +35 -0
- data/Rakefile +12 -0
- data/lib/rd_station_client/access_token/generate.rb +27 -0
- data/lib/rd_station_client/access_token/refresh.rb +29 -0
- data/lib/rd_station_client/access_token/storage.rb +38 -0
- data/lib/rd_station_client/authenticated.rb +63 -0
- data/lib/rd_station_client/base.rb +15 -0
- data/lib/rd_station_client/configuration.rb +13 -0
- data/lib/rd_station_client/contact/find.rb +40 -0
- data/lib/rd_station_client/contact/update.rb +51 -0
- data/lib/rd_station_client/event/create.rb +60 -0
- data/lib/rd_station_client/version.rb +5 -0
- data/lib/rd_station_client.rb +21 -0
- data/sig/rd_station_client.rbs +4 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0be5d4e9e92f68a2fb8ffbca1070c74c02c7f9fc8ee5a7cfe36f323a463ee14a
|
4
|
+
data.tar.gz: 99d1a9c4595154b2fad91804bf5c4d9bb0c7ea56d84c13426f6521f137b9ab1b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 83a8d1c77f69b80d7aaa66f270a71dd37b4e40c9fab9c9562112165036fcddb7cde8110d7222724757c6c1a8ad7eba76d4443a44fc3982dc62633678168ea971
|
7
|
+
data.tar.gz: 714b8cf0231199f161c5d49f2524908755af8a95364438d4415c38c27681b6bef4dbbc27048ca2e47bf68dda767bacb6990ffa2b00b6b81e71ef9c2f5af6a0ec
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-rspec
|
3
|
+
- rubocop-performance
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
SuggestExtensions: false
|
7
|
+
NewCops: enable
|
8
|
+
CacheRootDirectory: tmp
|
9
|
+
Exclude:
|
10
|
+
- 'vendor/**/*'
|
11
|
+
- 'bin/**/*'
|
12
|
+
- '.git/**/*'
|
13
|
+
- 'examples/**/*'
|
14
|
+
|
15
|
+
##### LAYOUT #####
|
16
|
+
|
17
|
+
Layout/FirstArrayElementIndentation:
|
18
|
+
Enabled: true
|
19
|
+
EnforcedStyle: consistent
|
20
|
+
|
21
|
+
Layout/FirstHashElementIndentation:
|
22
|
+
Enabled: true
|
23
|
+
EnforcedStyle: consistent
|
24
|
+
|
25
|
+
Layout/LineLength:
|
26
|
+
Max: 120
|
27
|
+
AllowedPatterns: ['(\A|\s)#']
|
28
|
+
|
29
|
+
##### STYLE #####
|
30
|
+
|
31
|
+
Style/PreferredHashMethods:
|
32
|
+
Enabled: true
|
33
|
+
Safe: false
|
34
|
+
EnforcedStyle: verbose
|
35
|
+
|
36
|
+
Style/SymbolArray:
|
37
|
+
Enabled: true
|
38
|
+
EnforcedStyle: percent
|
39
|
+
MinSize: 3
|
40
|
+
|
41
|
+
Style/WordArray:
|
42
|
+
Enabled: true
|
43
|
+
EnforcedStyle: percent
|
44
|
+
MinSize: 3
|
45
|
+
|
46
|
+
Style/MultilineBlockChain:
|
47
|
+
Enabled: false
|
48
|
+
|
49
|
+
Style/Lambda:
|
50
|
+
Enabled: true
|
51
|
+
EnforcedStyle: literal
|
52
|
+
|
53
|
+
Style/LambdaCall:
|
54
|
+
Enabled: false
|
55
|
+
|
56
|
+
Style/Documentation:
|
57
|
+
Enabled: false
|
58
|
+
|
59
|
+
Style/ClassAndModuleChildren:
|
60
|
+
Enabled: false
|
61
|
+
|
62
|
+
##### LINT #####
|
63
|
+
|
64
|
+
Lint/MissingSuper:
|
65
|
+
Enabled: false
|
66
|
+
|
67
|
+
##### NAMING #####
|
68
|
+
|
69
|
+
Naming/InclusiveLanguage:
|
70
|
+
Enabled: false
|
71
|
+
|
72
|
+
Naming/PredicateName:
|
73
|
+
ForbiddenPrefixes:
|
74
|
+
- is_
|
75
|
+
- have_
|
76
|
+
# allows `has_` predicate
|
77
|
+
|
78
|
+
###### METRICS #####
|
79
|
+
|
80
|
+
Metrics/AbcSize:
|
81
|
+
Enabled: true
|
82
|
+
Max: 22
|
83
|
+
|
84
|
+
Metrics/BlockLength:
|
85
|
+
Enabled: true
|
86
|
+
CountComments: false
|
87
|
+
Exclude:
|
88
|
+
- '**/*.gemspec'
|
89
|
+
- 'spec/**/*'
|
90
|
+
|
91
|
+
Metrics/ClassLength:
|
92
|
+
Max: 200
|
93
|
+
|
94
|
+
Metrics/MethodLength:
|
95
|
+
Enabled: true
|
96
|
+
CountAsOne: ['array', 'heredoc']
|
97
|
+
Max: 20
|
98
|
+
|
99
|
+
##### RSPEC #####
|
100
|
+
|
101
|
+
RSpec/ContextWording:
|
102
|
+
Prefixes:
|
103
|
+
- and
|
104
|
+
- but
|
105
|
+
- when
|
106
|
+
- with
|
107
|
+
- without
|
108
|
+
|
109
|
+
RSpec/ExampleLength:
|
110
|
+
Max: 20
|
111
|
+
|
112
|
+
RSpec/FilePath:
|
113
|
+
CustomTransform:
|
114
|
+
RDStationClient: rd_station_client
|
115
|
+
|
116
|
+
RSpec/MultipleMemoizedHelpers:
|
117
|
+
Enabled: false
|
118
|
+
|
119
|
+
RSpec/NestedGroups:
|
120
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
## [Unreleased]
|
2
|
+
|
3
|
+
## [0.2.0] - 2023-05-22
|
4
|
+
|
5
|
+
- Add FHTTPClient gem as a runtime dependence.
|
6
|
+
|
7
|
+
## [0.1.0] - 2023-02-22
|
8
|
+
|
9
|
+
- Initial release
|
10
|
+
- Add Base gem;
|
11
|
+
- Add Contact Find service;
|
12
|
+
- Add Contact Update service;
|
13
|
+
- Add Event Create service;
|
data/Gemfile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in rd_station_client.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
group :development do
|
9
|
+
gem 'rubocop'
|
10
|
+
gem 'rubocop-performance'
|
11
|
+
gem 'rubocop-rspec'
|
12
|
+
end
|
13
|
+
|
14
|
+
group :test do
|
15
|
+
gem 'rspec', '~> 3.0'
|
16
|
+
gem 'simplecov'
|
17
|
+
gem 'webmock'
|
18
|
+
end
|
19
|
+
|
20
|
+
group :development, :test do
|
21
|
+
gem 'pry'
|
22
|
+
gem 'pry-nav'
|
23
|
+
gem 'rake', '~> 13.0'
|
24
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rd_station_client (0.2.0)
|
5
|
+
connection_pool
|
6
|
+
dry-configurable
|
7
|
+
f_http_client (>= 0.2.0)
|
8
|
+
redis
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
activesupport (7.0.4.3)
|
14
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
15
|
+
i18n (>= 1.6, < 2)
|
16
|
+
minitest (>= 5.1)
|
17
|
+
tzinfo (~> 2.0)
|
18
|
+
addressable (2.8.1)
|
19
|
+
public_suffix (>= 2.0.2, < 6.0)
|
20
|
+
ast (2.4.2)
|
21
|
+
coderay (1.1.3)
|
22
|
+
concurrent-ruby (1.2.2)
|
23
|
+
connection_pool (2.3.0)
|
24
|
+
crack (0.4.5)
|
25
|
+
rexml
|
26
|
+
diff-lcs (1.5.0)
|
27
|
+
docile (1.4.0)
|
28
|
+
dry-configurable (1.0.1)
|
29
|
+
dry-core (~> 1.0, < 2)
|
30
|
+
zeitwerk (~> 2.6)
|
31
|
+
dry-core (1.0.0)
|
32
|
+
concurrent-ruby (~> 1.0)
|
33
|
+
zeitwerk (~> 2.6)
|
34
|
+
dry-initializer (3.1.1)
|
35
|
+
f_http_client (0.2.0)
|
36
|
+
activesupport
|
37
|
+
addressable
|
38
|
+
dry-configurable
|
39
|
+
dry-initializer
|
40
|
+
f_service (>= 0.3.0)
|
41
|
+
httparty
|
42
|
+
f_service (0.3.0)
|
43
|
+
hashdiff (1.0.1)
|
44
|
+
httparty (0.21.0)
|
45
|
+
mini_mime (>= 1.0.0)
|
46
|
+
multi_xml (>= 0.5.2)
|
47
|
+
i18n (1.12.0)
|
48
|
+
concurrent-ruby (~> 1.0)
|
49
|
+
json (2.6.3)
|
50
|
+
method_source (1.0.0)
|
51
|
+
mini_mime (1.1.2)
|
52
|
+
minitest (5.18.0)
|
53
|
+
multi_xml (0.6.0)
|
54
|
+
parallel (1.22.1)
|
55
|
+
parser (3.2.1.0)
|
56
|
+
ast (~> 2.4.1)
|
57
|
+
pry (0.14.2)
|
58
|
+
coderay (~> 1.1)
|
59
|
+
method_source (~> 1.0)
|
60
|
+
pry-nav (1.0.0)
|
61
|
+
pry (>= 0.9.10, < 0.15)
|
62
|
+
public_suffix (5.0.1)
|
63
|
+
rainbow (3.1.1)
|
64
|
+
rake (13.0.6)
|
65
|
+
redis (5.0.6)
|
66
|
+
redis-client (>= 0.9.0)
|
67
|
+
redis-client (0.12.2)
|
68
|
+
connection_pool
|
69
|
+
regexp_parser (2.7.0)
|
70
|
+
rexml (3.2.5)
|
71
|
+
rspec (3.12.0)
|
72
|
+
rspec-core (~> 3.12.0)
|
73
|
+
rspec-expectations (~> 3.12.0)
|
74
|
+
rspec-mocks (~> 3.12.0)
|
75
|
+
rspec-core (3.12.1)
|
76
|
+
rspec-support (~> 3.12.0)
|
77
|
+
rspec-expectations (3.12.2)
|
78
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
79
|
+
rspec-support (~> 3.12.0)
|
80
|
+
rspec-mocks (3.12.3)
|
81
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
82
|
+
rspec-support (~> 3.12.0)
|
83
|
+
rspec-support (3.12.0)
|
84
|
+
rubocop (1.45.1)
|
85
|
+
json (~> 2.3)
|
86
|
+
parallel (~> 1.10)
|
87
|
+
parser (>= 3.2.0.0)
|
88
|
+
rainbow (>= 2.2.2, < 4.0)
|
89
|
+
regexp_parser (>= 1.8, < 3.0)
|
90
|
+
rexml (>= 3.2.5, < 4.0)
|
91
|
+
rubocop-ast (>= 1.24.1, < 2.0)
|
92
|
+
ruby-progressbar (~> 1.7)
|
93
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
94
|
+
rubocop-ast (1.26.0)
|
95
|
+
parser (>= 3.2.1.0)
|
96
|
+
rubocop-capybara (2.17.1)
|
97
|
+
rubocop (~> 1.41)
|
98
|
+
rubocop-performance (1.16.0)
|
99
|
+
rubocop (>= 1.7.0, < 2.0)
|
100
|
+
rubocop-ast (>= 0.4.0)
|
101
|
+
rubocop-rspec (2.18.1)
|
102
|
+
rubocop (~> 1.33)
|
103
|
+
rubocop-capybara (~> 2.17)
|
104
|
+
ruby-progressbar (1.11.0)
|
105
|
+
simplecov (0.22.0)
|
106
|
+
docile (~> 1.1)
|
107
|
+
simplecov-html (~> 0.11)
|
108
|
+
simplecov_json_formatter (~> 0.1)
|
109
|
+
simplecov-html (0.12.3)
|
110
|
+
simplecov_json_formatter (0.1.4)
|
111
|
+
tzinfo (2.0.6)
|
112
|
+
concurrent-ruby (~> 1.0)
|
113
|
+
unicode-display_width (2.4.2)
|
114
|
+
webmock (3.18.1)
|
115
|
+
addressable (>= 2.8.0)
|
116
|
+
crack (>= 0.3.2)
|
117
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
118
|
+
zeitwerk (2.6.7)
|
119
|
+
|
120
|
+
PLATFORMS
|
121
|
+
x86_64-darwin-22
|
122
|
+
x86_64-linux
|
123
|
+
|
124
|
+
DEPENDENCIES
|
125
|
+
pry
|
126
|
+
pry-nav
|
127
|
+
rake (~> 13.0)
|
128
|
+
rd_station_client!
|
129
|
+
rspec (~> 3.0)
|
130
|
+
rubocop
|
131
|
+
rubocop-performance
|
132
|
+
rubocop-rspec
|
133
|
+
simplecov
|
134
|
+
webmock
|
135
|
+
|
136
|
+
BUNDLED WITH
|
137
|
+
2.4.6
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Bruno Vicenzo
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# RDStationClient
|
2
|
+
|
3
|
+
TODO: Delete this and the text below, and describe your gem
|
4
|
+
|
5
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rd_station_client`. To experiment with that code, run `bin/console` for an interactive prompt.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
10
|
+
|
11
|
+
Install the gem and add to the application's Gemfile by executing:
|
12
|
+
|
13
|
+
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
14
|
+
|
15
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
16
|
+
|
17
|
+
$ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Development
|
24
|
+
|
25
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
26
|
+
|
27
|
+
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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rd_station_client.
|
32
|
+
|
33
|
+
## License
|
34
|
+
|
35
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RDStationClient
|
4
|
+
module AccessToken
|
5
|
+
class Generate < RDStationClient::Base
|
6
|
+
cache_strategy :null
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def make_request
|
11
|
+
self.class.post(formatted_path, headers: headers, body: body)
|
12
|
+
end
|
13
|
+
|
14
|
+
def path_template
|
15
|
+
'/auth/token'
|
16
|
+
end
|
17
|
+
|
18
|
+
def body
|
19
|
+
{
|
20
|
+
client_id: config.rd_client_id,
|
21
|
+
client_secret: config.rd_secret,
|
22
|
+
code: config.rd_code
|
23
|
+
}.to_json
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RDStationClient
|
4
|
+
module AccessToken
|
5
|
+
class Refresh < RDStationClient::Base
|
6
|
+
option :refresh_token
|
7
|
+
|
8
|
+
cache_strategy :null
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def make_request
|
13
|
+
self.class.post(formatted_path, headers: headers, body: body)
|
14
|
+
end
|
15
|
+
|
16
|
+
def path_template
|
17
|
+
'/auth/token'
|
18
|
+
end
|
19
|
+
|
20
|
+
def body
|
21
|
+
{
|
22
|
+
client_id: config.rd_client_id,
|
23
|
+
client_secret: config.rd_secret,
|
24
|
+
refresh_token: refresh_token
|
25
|
+
}.to_json
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RDStationClient
|
4
|
+
module AccessToken
|
5
|
+
class Storage
|
6
|
+
extend Forwardable
|
7
|
+
include Singleton
|
8
|
+
|
9
|
+
LIB_PREFIX = 'rd_station_client'
|
10
|
+
|
11
|
+
delegate %i[with] => :@pool
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@pool = ::ConnectionPool.new(size: config.redis.pool_size) do
|
15
|
+
Redis.new(config.redis.connection_params)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def find(key)
|
20
|
+
with { |connection| connection.get(key_path(key)) }
|
21
|
+
end
|
22
|
+
|
23
|
+
def persist(key, value)
|
24
|
+
with { |connection| connection.set(key_path(key), value) }
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def config
|
30
|
+
@config ||= RDStationClient::Configuration.config
|
31
|
+
end
|
32
|
+
|
33
|
+
def key_path(key)
|
34
|
+
[LIB_PREFIX, key].join(':')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RDStationClient
|
4
|
+
class Authenticated < RDStationClient::Base
|
5
|
+
AUTH_DATA_KEY = :auth_data
|
6
|
+
|
7
|
+
def run
|
8
|
+
ensure_access_token
|
9
|
+
.and_then do
|
10
|
+
super.on_failure(:unauthorized) do
|
11
|
+
return refresh_access_token.and_then { super }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def ensure_access_token
|
19
|
+
return Success(:token_retrieved) if access_token.present?
|
20
|
+
|
21
|
+
RDStationClient::AccessToken::Generate.()
|
22
|
+
.and_then do |auth_data|
|
23
|
+
store_auth_data(auth_data)
|
24
|
+
Success(:token_generated)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def refresh_access_token
|
29
|
+
RDStationClient::AccessToken::Refresh.(refresh_token: refresh_token)
|
30
|
+
.and_then do |auth_data|
|
31
|
+
store_auth_data(auth_data)
|
32
|
+
Success(:token_generated)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def access_token
|
37
|
+
auth_data[:access_token]
|
38
|
+
end
|
39
|
+
|
40
|
+
def refresh_token
|
41
|
+
auth_data[:refresh_token]
|
42
|
+
end
|
43
|
+
|
44
|
+
def auth_data
|
45
|
+
@auth_data ||= JSON.parse(storage.find(AUTH_DATA_KEY).presence || '{}', symbolize_names: true)
|
46
|
+
end
|
47
|
+
|
48
|
+
def store_auth_data(auth_data)
|
49
|
+
storage.persist(AUTH_DATA_KEY, auth_data)
|
50
|
+
@auth_data = auth_data
|
51
|
+
|
52
|
+
nil
|
53
|
+
end
|
54
|
+
|
55
|
+
def storage
|
56
|
+
@storage ||= RDStationClient::AccessToken::Storage.instance
|
57
|
+
end
|
58
|
+
|
59
|
+
def headers
|
60
|
+
super.merge('Authorization' => "Bearer #{access_token}")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RDStationClient
|
4
|
+
class Base < FHTTPClient::Base
|
5
|
+
def self.config
|
6
|
+
RDStationClient::Configuration.config
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def headers
|
12
|
+
@headers.merge('Content-Type' => 'application/json')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RDStationClient
|
4
|
+
class Configuration < FHTTPClient::Configuration
|
5
|
+
setting :rd_client_id
|
6
|
+
setting :rd_secret
|
7
|
+
setting :rd_code
|
8
|
+
setting :redis do
|
9
|
+
setting :pool_size, default: 5
|
10
|
+
setting :connection_params, default: {}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RDStationClient
|
4
|
+
module Contact
|
5
|
+
# Update a contact at RDStation based on this documentation: https://developers.rdstation.com/reference/get_platform-contacts-identifier-value
|
6
|
+
#
|
7
|
+
# Ex:
|
8
|
+
# RDStationClient::Contact::Find.(path_params: { identifier_type: 'email', identifier_value: 'contact@email.com' })
|
9
|
+
#
|
10
|
+
# RDStationClient::Contact::Find.(path_params: { identifier_type: 'uuid', identifier_value: 'adf6d3d6-31da-41bd-8e5c-b3fbfbafa8a8' })
|
11
|
+
#
|
12
|
+
# RDStationClient::Contact::Find.(email: 'contact@email.com')
|
13
|
+
#
|
14
|
+
# RDStationClient::Contact::Find.(uuid: 'adf6d3d6-31da-41bd-8e5c-b3fbfbafa8a8')
|
15
|
+
class Find < RDStationClient::Authenticated
|
16
|
+
option :uuid, default: -> {}
|
17
|
+
option :email, default: -> {}
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def make_request
|
22
|
+
self.class.get(formatted_path, headers: headers)
|
23
|
+
end
|
24
|
+
|
25
|
+
def path_template
|
26
|
+
'/platform/contacts/%<identifier_type>s:%<identifier_value>s'
|
27
|
+
end
|
28
|
+
|
29
|
+
def path_params
|
30
|
+
if email.present?
|
31
|
+
{ identifier_type: :email, identifier_value: email }
|
32
|
+
elsif uuid.present?
|
33
|
+
{ identifier_type: :uuid, identifier_value: uuid }
|
34
|
+
else
|
35
|
+
super
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RDStationClient
|
4
|
+
module Contact
|
5
|
+
# Update a contact at RDStation based on this documentation: https://developers.rdstation.com/reference/patch_platform-contacts-identifier-value
|
6
|
+
# Ex:
|
7
|
+
# RDStationClient::Contact::Update.(
|
8
|
+
# path_params: { identifier_type: 'email', identifier_value: 'contact@email.com' },
|
9
|
+
# body: { name: 'John Doe', website: 'http://mysite.com', bio: 'My name is John Doe' }
|
10
|
+
# )
|
11
|
+
#
|
12
|
+
# RDStationClient::Contact::Update.(
|
13
|
+
# path_params: { identifier_type: 'uuid', identifier_value: 'adf6d3d6-31da-41bd-8e5c-b3fbfbafa8a8' }
|
14
|
+
# body: { name: 'John Doe', website: 'http://mysite.com', bio: 'My name is John Doe' }
|
15
|
+
# )
|
16
|
+
#
|
17
|
+
# RDStationClient::Contact::Update.(
|
18
|
+
# email: 'contact@email.com'
|
19
|
+
# body: { name: 'John Doe', website: 'http://mysite.com', bio: 'My name is John Doe' }
|
20
|
+
# )
|
21
|
+
#
|
22
|
+
# RDStationClient::Contact::Update.(
|
23
|
+
# uuid: 'adf6d3d6-31da-41bd-8e5c-b3fbfbafa8a8',
|
24
|
+
# body: { name: 'John Doe', website: 'http://mysite.com', bio: 'My name is John Doe' }
|
25
|
+
# )
|
26
|
+
class Update < RDStationClient::Authenticated
|
27
|
+
option :uuid, default: -> {}
|
28
|
+
option :email, default: -> {}
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def make_request
|
33
|
+
self.class.patch(formatted_path, headers: headers, body: body.to_json)
|
34
|
+
end
|
35
|
+
|
36
|
+
def path_template
|
37
|
+
'/platform/contacts/%<identifier_type>s:%<identifier_value>s'
|
38
|
+
end
|
39
|
+
|
40
|
+
def path_params
|
41
|
+
if email.present?
|
42
|
+
{ identifier_type: :email, identifier_value: email }
|
43
|
+
elsif uuid.present?
|
44
|
+
{ identifier_type: :uuid, identifier_value: uuid }
|
45
|
+
else
|
46
|
+
super
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RDStationClient
|
4
|
+
module Event
|
5
|
+
# Create an event at RDStation based on this documentation: https://developers.rdstation.com/reference/eventos-padr%C3%A3o
|
6
|
+
# Ex:
|
7
|
+
# RDStationClient::Event::Create.(
|
8
|
+
# body: {
|
9
|
+
# event_type: 'CONVERSION',
|
10
|
+
# event_family: 'CDP',
|
11
|
+
# payload: {
|
12
|
+
# conversion_identifier: 'Name of the conversion event',
|
13
|
+
# name: 'Nome',
|
14
|
+
# email: 'email@email.com',
|
15
|
+
# job_title: 'job title value',
|
16
|
+
# state: 'state of the contact',
|
17
|
+
# city: 'city of the contact',
|
18
|
+
# country: 'country of the contact',
|
19
|
+
# personal_phone: 'phone of the contact',
|
20
|
+
# mobile_phone: 'mobile_phone of the contact',
|
21
|
+
# twitter: 'twitter handler of the contact',
|
22
|
+
# facebook: 'facebook name of the contact',
|
23
|
+
# linkedin: 'linkedin user name of the contact',
|
24
|
+
# website: 'website of the contact',
|
25
|
+
# cf_custom_field_api_identifier: 'custom field value',
|
26
|
+
# company_name: 'company name',
|
27
|
+
# company_site: 'company website',
|
28
|
+
# company_address: 'company address',
|
29
|
+
# client_tracking_id: 'lead tracking client_id',
|
30
|
+
# traffic_source: 'Google',
|
31
|
+
# traffic_medium: 'cpc',
|
32
|
+
# traffic_campaign: 'easter-50-off',
|
33
|
+
# traffic_value: 'easter eggs',
|
34
|
+
# tags: [
|
35
|
+
# mql',
|
36
|
+
# 2019'
|
37
|
+
# ],
|
38
|
+
# available_for_mailing: true,
|
39
|
+
# legal_bases: [
|
40
|
+
# {
|
41
|
+
# category: 'communications',
|
42
|
+
# type: 'consent',
|
43
|
+
# status: 'granted'
|
44
|
+
# }
|
45
|
+
# ]
|
46
|
+
# }
|
47
|
+
# }
|
48
|
+
class Create < RDStationClient::Authenticated
|
49
|
+
private
|
50
|
+
|
51
|
+
def make_request
|
52
|
+
self.class.post(formatted_path, headers: headers, body: body.to_json)
|
53
|
+
end
|
54
|
+
|
55
|
+
def path_template
|
56
|
+
'/platform/events'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'f_http_client'
|
4
|
+
require 'singleton'
|
5
|
+
require 'redis'
|
6
|
+
require 'connection_pool'
|
7
|
+
require 'forwardable'
|
8
|
+
|
9
|
+
require_relative 'rd_station_client/version'
|
10
|
+
require_relative 'rd_station_client/configuration'
|
11
|
+
require_relative 'rd_station_client/base'
|
12
|
+
require_relative 'rd_station_client/access_token/generate'
|
13
|
+
require_relative 'rd_station_client/access_token/storage'
|
14
|
+
require_relative 'rd_station_client/access_token/refresh'
|
15
|
+
require_relative 'rd_station_client/authenticated'
|
16
|
+
require_relative 'rd_station_client/contact/find'
|
17
|
+
require_relative 'rd_station_client/contact/update'
|
18
|
+
require_relative 'rd_station_client/event/create'
|
19
|
+
|
20
|
+
module RDStationClient
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rd_station_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Fretadao Tech Team
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-05-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: connection_pool
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: redis
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: dry-configurable
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: f_http_client
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.2.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.2.0
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- tech@fretadao.com.br
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".rspec"
|
77
|
+
- ".rubocop.yml"
|
78
|
+
- CHANGELOG.md
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- lib/rd_station_client.rb
|
85
|
+
- lib/rd_station_client/access_token/generate.rb
|
86
|
+
- lib/rd_station_client/access_token/refresh.rb
|
87
|
+
- lib/rd_station_client/access_token/storage.rb
|
88
|
+
- lib/rd_station_client/authenticated.rb
|
89
|
+
- lib/rd_station_client/base.rb
|
90
|
+
- lib/rd_station_client/configuration.rb
|
91
|
+
- lib/rd_station_client/contact/find.rb
|
92
|
+
- lib/rd_station_client/contact/update.rb
|
93
|
+
- lib/rd_station_client/event/create.rb
|
94
|
+
- lib/rd_station_client/version.rb
|
95
|
+
- sig/rd_station_client.rbs
|
96
|
+
homepage: https://github.com/Fretadao/rd_station_client
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
metadata:
|
100
|
+
homepage_uri: https://github.com/Fretadao/rd_station_client
|
101
|
+
source_code_uri: https://github.com/Fretadao/rd_station_client
|
102
|
+
changelog_uri: https://github.com/Fretadao/rd_station_client/blob/master/CHANGELOG.md
|
103
|
+
rubygems_mfa_required: 'true'
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: 3.0.0
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubygems_version: 3.3.5
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: Gem to provide service clients to integrate with RD Station API services
|
123
|
+
test_files: []
|