reattract 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d788029cfabbe3aa6a894388ea0dac86ccba0891deb9b5eecd8366d3e931c412
4
+ data.tar.gz: b83d5843485a28165e9e1c5d5cb1eb3d97018861ab8dd8463854229d6962060e
5
+ SHA512:
6
+ metadata.gz: f4f36d5e427823a146c68f43b9f5b7c0b356f142ae4b9ce08c293138a0acc6654d1c7cc92805773e075426e845850d958ca971608a6c6c1cf2bfb96b02d01637
7
+ data.tar.gz: 5298603faf71b6c7dd81fe9d347dfc06cedcdf56d7c4108e8e3dd17e0eda69b9cc5faced3ebceb0df255c9bbce885d1534f960c8ca19edb64a53521a030ff724
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,51 @@
1
+ require:
2
+ - rubocop-rake
3
+ - rubocop-rspec
4
+ - rubocop-performance
5
+
6
+ # https://docs.rubocop.org/rubocop/configuration.html
7
+ AllCops:
8
+ NewCops: enable
9
+ Exclude:
10
+ - 'Guardfile'
11
+ - 'reattract.gemspec'
12
+ - 'bin/**/*'
13
+
14
+ Layout/LineLength:
15
+ Max: 120
16
+ AllowedPatterns: ['\A#'] # Ignore comments
17
+
18
+ Layout/HashAlignment:
19
+ EnforcedColonStyle: table
20
+ EnforcedHashRocketStyle: table
21
+
22
+ Metrics/AbcSize:
23
+ Max: 25
24
+
25
+ Metrics/ClassLength:
26
+ CountAsOne:
27
+ - heredoc
28
+ - hash
29
+ - array
30
+
31
+ Metrics/ModuleLength:
32
+ CountAsOne:
33
+ - heredoc
34
+ - hash
35
+ - array
36
+
37
+ Metrics/MethodLength:
38
+ Max: 20
39
+ CountAsOne:
40
+ - heredoc
41
+ - hash
42
+ - array
43
+
44
+ Metrics/ParameterLists:
45
+ Max: 15
46
+
47
+ RSpec/MultipleExpectations:
48
+ Max: 4
49
+
50
+ RSpec/MultipleMemoizedHelpers:
51
+ Max: 7
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-02-27
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in reattract.gemspec
6
+ gemspec
7
+
8
+ gem 'guard', '~> 2.18'
9
+ gem 'guard-rspec', '~> 4.7'
10
+ gem 'guard-rubocop', '~> 1.5'
11
+
12
+ gem 'rake', '~> 13.0'
13
+ gem 'rspec', '~> 3.0'
14
+ gem 'rubocop', '~> 1.46'
15
+ gem 'rubocop-performance', '~> 1.16'
16
+ gem 'rubocop-rake', '~> 0.6.0'
17
+ gem 'rubocop-rspec', '~> 2.18'
18
+
19
+ gem 'guard-kjell', '~> 1.0'
20
+
21
+ gem 'solargraph', '~> 0.48.0'
data/Gemfile.lock ADDED
@@ -0,0 +1,148 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ reattract (0.4.1)
5
+ jwt (~> 2.7.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ backport (1.2.0)
12
+ benchmark (0.2.1)
13
+ coderay (1.1.3)
14
+ diff-lcs (1.5.0)
15
+ e2mmap (0.1.0)
16
+ ffi (1.15.5)
17
+ formatador (1.1.0)
18
+ guard (2.18.0)
19
+ formatador (>= 0.2.4)
20
+ listen (>= 2.7, < 4.0)
21
+ lumberjack (>= 1.0.12, < 2.0)
22
+ nenv (~> 0.1)
23
+ notiffany (~> 0.0)
24
+ pry (>= 0.13.0)
25
+ shellany (~> 0.0)
26
+ thor (>= 0.18.1)
27
+ guard-compat (1.2.1)
28
+ guard-kjell (1.0.2)
29
+ guard-compat
30
+ guard-rspec (4.7.3)
31
+ guard (~> 2.1)
32
+ guard-compat (~> 1.1)
33
+ rspec (>= 2.99.0, < 4.0)
34
+ guard-rubocop (1.5.0)
35
+ guard (~> 2.0)
36
+ rubocop (< 2.0)
37
+ jaro_winkler (1.5.4)
38
+ json (2.6.3)
39
+ jwt (2.7.0)
40
+ kramdown (2.4.0)
41
+ rexml
42
+ kramdown-parser-gfm (1.1.0)
43
+ kramdown (~> 2.0)
44
+ listen (3.8.0)
45
+ rb-fsevent (~> 0.10, >= 0.10.3)
46
+ rb-inotify (~> 0.9, >= 0.9.10)
47
+ lumberjack (1.2.8)
48
+ method_source (1.0.0)
49
+ nenv (0.3.0)
50
+ nokogiri (1.14.2-arm64-darwin)
51
+ racc (~> 1.4)
52
+ notiffany (0.1.3)
53
+ nenv (~> 0.1)
54
+ shellany (~> 0.0)
55
+ parallel (1.22.1)
56
+ parser (3.2.1.0)
57
+ ast (~> 2.4.1)
58
+ pry (0.14.2)
59
+ coderay (~> 1.1)
60
+ method_source (~> 1.0)
61
+ racc (1.6.2)
62
+ rainbow (3.1.1)
63
+ rake (13.0.6)
64
+ rb-fsevent (0.11.2)
65
+ rb-inotify (0.10.1)
66
+ ffi (~> 1.0)
67
+ regexp_parser (2.7.0)
68
+ reverse_markdown (2.1.1)
69
+ nokogiri
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.46.0)
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.26.0, < 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-rake (0.6.0)
102
+ rubocop (~> 1.0)
103
+ rubocop-rspec (2.18.1)
104
+ rubocop (~> 1.33)
105
+ rubocop-capybara (~> 2.17)
106
+ ruby-progressbar (1.11.0)
107
+ shellany (0.0.1)
108
+ solargraph (0.48.0)
109
+ backport (~> 1.2)
110
+ benchmark
111
+ bundler (>= 1.17.2)
112
+ diff-lcs (~> 1.4)
113
+ e2mmap
114
+ jaro_winkler (~> 1.5)
115
+ kramdown (~> 2.3)
116
+ kramdown-parser-gfm (~> 1.1)
117
+ parser (~> 3.0)
118
+ reverse_markdown (>= 1.0.5, < 3)
119
+ rubocop (>= 0.52)
120
+ thor (~> 1.0)
121
+ tilt (~> 2.0)
122
+ yard (~> 0.9, >= 0.9.24)
123
+ thor (1.2.1)
124
+ tilt (2.1.0)
125
+ unicode-display_width (2.4.2)
126
+ webrick (1.7.0)
127
+ yard (0.9.28)
128
+ webrick (~> 1.7.0)
129
+
130
+ PLATFORMS
131
+ arm64-darwin-22
132
+
133
+ DEPENDENCIES
134
+ guard (~> 2.18)
135
+ guard-kjell (~> 1.0)
136
+ guard-rspec (~> 4.7)
137
+ guard-rubocop (~> 1.5)
138
+ rake (~> 13.0)
139
+ reattract!
140
+ rspec (~> 3.0)
141
+ rubocop (~> 1.46)
142
+ rubocop-performance (~> 1.16)
143
+ rubocop-rake (~> 0.6.0)
144
+ rubocop-rspec (~> 2.18)
145
+ solargraph (~> 0.48.0)
146
+
147
+ BUNDLED WITH
148
+ 2.3.26
data/Guardfile ADDED
@@ -0,0 +1,86 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
25
+ # * 'just' rspec: 'rspec'
26
+
27
+ guard :rspec, cmd: "bundle exec rspec" do
28
+ require "guard/rspec/dsl"
29
+ dsl = Guard::RSpec::Dsl.new(self)
30
+
31
+ # Feel free to open issues for suggestions and improvements
32
+
33
+ # RSpec files
34
+ rspec = dsl.rspec
35
+ watch(rspec.spec_helper) { rspec.spec_dir }
36
+ watch(rspec.spec_support) { rspec.spec_dir }
37
+ watch(rspec.spec_files)
38
+
39
+ # Ruby files
40
+ ruby = dsl.ruby
41
+ dsl.watch_spec_files_for(ruby.lib_files)
42
+
43
+ # Rails files
44
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
45
+ dsl.watch_spec_files_for(rails.app_files)
46
+ dsl.watch_spec_files_for(rails.views)
47
+
48
+ watch(rails.controllers) do |m|
49
+ [
50
+ rspec.spec.call("routing/#{m[1]}_routing"),
51
+ rspec.spec.call("controllers/#{m[1]}_controller"),
52
+ rspec.spec.call("acceptance/#{m[1]}")
53
+ ]
54
+ end
55
+
56
+ # Rails config changes
57
+ watch(rails.spec_helper) { rspec.spec_dir }
58
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
59
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
60
+
61
+ # Capybara features specs
62
+ watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
63
+ watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
64
+
65
+ # Turnip features and steps
66
+ watch(%r{^spec/acceptance/(.+)\.feature$})
67
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
68
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
69
+ end
70
+ end
71
+
72
+ guard :rubocop do
73
+ watch(%r{.+\.rb$})
74
+ watch(%r{(?:.+/)?\.rubocop(?:_todo)?\.yml$}) { |m| File.dirname(m[0]) }
75
+ end
76
+
77
+ guard :kjell, cmd: 'bundle install' do
78
+ watch(%r{Gemfile$})
79
+ watch(%r{reattract.gemspec$})
80
+ end
81
+
82
+ guard :kjell, cmd: 'gem build reattract.gemspec' do
83
+ watch(%r{.+\.rb$})
84
+ watch(%r{Gemfile$})
85
+ watch(%r{reattract.gemspec$})
86
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Justin Burris
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,33 @@
1
+ # Reattract
2
+
3
+ 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/reattract/api`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add reattract_api
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install reattract_api
16
+
17
+ ## Usage
18
+
19
+ TODO: Write usage instructions here
20
+
21
+ ## Development
22
+
23
+ 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.
24
+
25
+ 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).
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/reattract.
30
+
31
+ ## License
32
+
33
+ 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,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: %i[spec]
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Reattract
4
+ # Allows for configuration oof reattract connections
5
+ class Configuration
6
+ attr_accessor :public_key, :secret_key, :api_version, :api_host, :use_ssl, :port
7
+
8
+ def initialize
9
+ @api_host = 'api.reattract.io'
10
+ @api_version = '/v1'
11
+ @use_ssl = true
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
4
+
5
+ module Reattract
6
+ # Handles the construction of the connection object
7
+ class Connection
8
+ attr_reader :authorization, :resource_uri
9
+
10
+ def initialize(authorization:, path:)
11
+ @resource_uri = build_uri
12
+ @resource_uri.path += path
13
+ @authorization = authorization
14
+ end
15
+
16
+ def get(query: {})
17
+ resource_uri.query = query.to_query
18
+ request = build_request(Net::HTTP::Get)
19
+
20
+ make_request(request)
21
+ end
22
+
23
+ def patch(body: {})
24
+ request = build_request(Net::HTTP::Patch, body: body)
25
+
26
+ make_request(request)
27
+ end
28
+
29
+ def put(body: {})
30
+ request = build_request(Net::HTTP::Put, body: body)
31
+
32
+ make_request(request)
33
+ end
34
+
35
+ def post(body: {})
36
+ request = build_request(Net::HTTP::Post, body: body)
37
+
38
+ make_request(request)
39
+ end
40
+
41
+ private
42
+
43
+ def make_request(request)
44
+ parse_response(client.request(request))
45
+ end
46
+
47
+ def parse_response(response)
48
+ return if response.body.empty?
49
+
50
+ pagination = extract_pagination(response)
51
+ JSON.parse(response.body, symbolize_names: true).tap do |parsed_response|
52
+ parsed_response[:pagination] = pagination if pagination
53
+ end
54
+ end
55
+
56
+ def extract_pagination(response)
57
+ return if response['Page-Items'].nil?
58
+
59
+ {
60
+ page_items: response['Page-Items'].to_i,
61
+ current_page: response['Current-Page'].to_i,
62
+ total_pages: response['Total-Pages'].to_i,
63
+ total_count: response['Total-Count'].to_i
64
+ }
65
+ end
66
+
67
+ def build_request(method_class, body: nil)
68
+ method_class.new(resource_uri).tap do |request|
69
+ request['Content-Type'] = 'application/json'
70
+ request['Accept'] = 'application/json'
71
+ request['Authorization'] = authorization
72
+ request.body = body.to_json if body
73
+ end
74
+ end
75
+
76
+ def client
77
+ Net::HTTP.new(resource_uri.host, resource_uri.port).tap do |http|
78
+ http.use_ssl = true if Reattract.use_ssl
79
+ end
80
+ end
81
+
82
+ def build_uri
83
+ attributes = { host: Reattract.api_host, path: Reattract.api_version }
84
+
85
+ attributes[:port] = configured_port if configured_port?
86
+
87
+ uri_module.build(attributes)
88
+ end
89
+
90
+ def configured_port?
91
+ !configured_port.zero?
92
+ end
93
+
94
+ def configured_port
95
+ Reattract.port.to_i
96
+ end
97
+
98
+ def uri_module
99
+ Reattract.use_ssl ? URI::HTTPS : URI::HTTP
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'jwt'
4
+
5
+ module Reattract
6
+ # Handles generation of JWTs
7
+ class JwtGenerator
8
+ ALGO_HMAC_256 = 'HS256'
9
+
10
+ attr_accessor :expired_at, :scopes
11
+
12
+ def initialize(expired_at: default_exp, scopes: nil)
13
+ @expired_at = expired_at.to_i
14
+ @scopes = scopes&.join(',')
15
+ end
16
+
17
+ def generate
18
+ JWT.encode payload, hmac_secret, algorithm
19
+ end
20
+
21
+ private
22
+
23
+ def hmac_secret
24
+ Reattract.secret_key
25
+ end
26
+
27
+ def algorithm
28
+ ALGO_HMAC_256
29
+ end
30
+
31
+ def payload
32
+ default_payload.tap do |hash|
33
+ hash[:scp] = scopes if scopes
34
+ end
35
+ end
36
+
37
+ def default_payload
38
+ {
39
+ exp: expired_at,
40
+ nbf: jwt_created,
41
+ iss: Reattract.public_key,
42
+ iat: jwt_created
43
+ }
44
+ end
45
+
46
+ def jwt_created
47
+ Time.zone.now.to_i
48
+ end
49
+
50
+ def default_exp
51
+ 1.week.from_now
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Reattract
4
+ # Makes requests using the Connection object
5
+ class Request
6
+ attr_accessor :connection
7
+
8
+ def initialize(path:, bearer_token: generate_bearer)
9
+ @connection = Reattract::Connection.new(
10
+ authorization: authorization(bearer_token),
11
+ path: path
12
+ )
13
+ end
14
+
15
+ def get(query: {}, pagination: nil, sort: nil)
16
+ if pagination
17
+ query[:page] = pagination[:page]
18
+ query[:limit] = pagination[:limit]
19
+ end
20
+ query[:s] = sort if sort
21
+ connection.get(query: query)
22
+ end
23
+
24
+ def patch(body: {})
25
+ connection.patch(body: body)
26
+ end
27
+
28
+ def post(body: {})
29
+ connection.post(body: body)
30
+ end
31
+
32
+ def put(body: {})
33
+ connection.put(body: body)
34
+ end
35
+
36
+ private
37
+
38
+ def generate_bearer
39
+ Reattract::JwtGenerator.new.generate
40
+ end
41
+
42
+ def prepare_request_with_body(req, body)
43
+ req.url endpoint
44
+ req.body = body.to_json
45
+ end
46
+
47
+ def authorization(bearer_token)
48
+ "Bearer #{bearer_token}"
49
+ end
50
+
51
+ def conn
52
+ @conn ||= Connection.build(authorization: authorization)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Reattract
4
+ # /v1/customer_events
5
+ class AppEvent
6
+ class << self
7
+ def create(event_name:, user_id:, payload: {})
8
+ request.post(
9
+ body: {
10
+ payload: payload,
11
+ event_name: event_name,
12
+ organization_user_id: user_id
13
+ }
14
+ )
15
+ end
16
+
17
+ private
18
+
19
+ def request
20
+ Reattract::Request.new(path: '/customer_events')
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Reattract
4
+ # /v1/campaigns
5
+ class Campaign
6
+ class << self
7
+ def list(limit: 20, page: 1, order: ['id desc'])
8
+ request.get(
9
+ sort: order,
10
+ pagination: {
11
+ limit: limit,
12
+ page: page
13
+ }
14
+ )
15
+ end
16
+
17
+ private
18
+
19
+ def request
20
+ Reattract::Request.new(path: '/campaigns')
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Reattract
4
+ # /v1/organization_customers
5
+ class Customer
6
+ class << self
7
+ def create(user_id:, **kwargs)
8
+ collection_request.post(
9
+ body: kwargs.merge(organization_user_id: user_id)
10
+ )
11
+ end
12
+
13
+ def update(user_id:, **kwargs)
14
+ member_request(user_id: user_id).patch(
15
+ body: kwargs
16
+ )
17
+ end
18
+
19
+ def get(user_id:)
20
+ member_request(user_id: user_id).get
21
+ end
22
+
23
+ def list(limit: 20, page: 1, order: ['id desc'])
24
+ collection_request.get(
25
+ sort: order,
26
+ pagination: {
27
+ limit: limit,
28
+ page: page
29
+ }
30
+ )
31
+ end
32
+
33
+ private
34
+
35
+ def collection_request
36
+ Reattract::Request.new(path: '/organization_customers')
37
+ end
38
+
39
+ def member_request(user_id:)
40
+ Reattract::Request.new(path: "/organization_customers/#{user_id}")
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Reattract
4
+ # /v1/invite_codes
5
+ class InviteCode
6
+ class << self
7
+ def create(user_id:, campaign_id: nil)
8
+ collection_request.post(
9
+ body: {
10
+ organization_user_id: user_id,
11
+ campaign_id: campaign_id
12
+ }
13
+ )
14
+ end
15
+
16
+ def list(limit: 20, page: 1, order: ['id desc'])
17
+ collection_request.get(
18
+ sort: order,
19
+ pagination: {
20
+ limit: limit,
21
+ page: page
22
+ }
23
+ )
24
+ end
25
+
26
+ private
27
+
28
+ def collection_request
29
+ Reattract::Request.new(path: '/invite_codes')
30
+ end
31
+
32
+ def member_request(user_id:)
33
+ Reattract::Request.new(path: "/invite_codes/#{user_id}")
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Reattract
4
+ # /v1/invite_conversions
5
+ class InviteConversion
6
+ class << self
7
+ def create(user_id:, invite_code: nil, invite_session_id: nil, customer: {})
8
+ request.post(
9
+ body: {
10
+ organization_user_id: user_id,
11
+ unique_code: invite_code,
12
+ invite_session_id: invite_session_id,
13
+ organization_customer: customer
14
+ }
15
+ )
16
+ end
17
+
18
+ def list(limit: 20, page: 1, order: ['id desc'])
19
+ request.get(
20
+ sort: order,
21
+ pagination: {
22
+ limit: limit,
23
+ page: page
24
+ }
25
+ )
26
+ end
27
+
28
+ private
29
+
30
+ def request
31
+ Reattract::Request.new(path: '/invite_conversions')
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Reattract
4
+ # /v1/invite_sessions
5
+ class InviteSession
6
+ class << self
7
+ def get(id:)
8
+ member_request(id: id).get
9
+ end
10
+
11
+ private
12
+
13
+ def member_request(id:)
14
+ Reattract::Request.new(path: "/invite_sessions/#{id}")
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Reattract
4
+ VERSION = '0.4.1'
5
+ end
data/lib/reattract.rb ADDED
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+
5
+ require_relative 'reattract/version'
6
+ require_relative 'reattract/configuration'
7
+ require_relative 'reattract/jwt_generator'
8
+ require_relative 'reattract/connection'
9
+ require_relative 'reattract/request'
10
+ require_relative 'reattract/resources/app_event'
11
+ require_relative 'reattract/resources/campaign'
12
+ require_relative 'reattract/resources/customer'
13
+ require_relative 'reattract/resources/invite_code'
14
+ require_relative 'reattract/resources/invite_conversion'
15
+ require_relative 'reattract/resources/invite_session'
16
+
17
+ # Core reattract module. Enables connection to the reattract API
18
+ module Reattract
19
+ @config = Reattract::Configuration.new
20
+
21
+ class << self
22
+ extend Forwardable
23
+
24
+ attr_reader :config
25
+
26
+ def_delegators :@config, :public_key, :public_key=
27
+ def_delegators :@config, :secret_key, :secret_key=
28
+ def_delegators :@config, :api_version, :api_version=
29
+ def_delegators :@config, :api_host, :api_host=
30
+ def_delegators :@config, :use_ssl, :use_ssl=
31
+ def_delegators :@config, :port, :port=
32
+
33
+ def configure
34
+ yield(configuration)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,6 @@
1
+ module Reattract
2
+ module Api
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reattract
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.1
5
+ platform: ruby
6
+ authors:
7
+ - Justin Burris
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-04-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jwt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.7.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.7.0
27
+ description:
28
+ email:
29
+ - justin@reattract.io
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rspec"
35
+ - ".rubocop.yml"
36
+ - CHANGELOG.md
37
+ - Gemfile
38
+ - Gemfile.lock
39
+ - Guardfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - lib/reattract.rb
44
+ - lib/reattract/configuration.rb
45
+ - lib/reattract/connection.rb
46
+ - lib/reattract/jwt_generator.rb
47
+ - lib/reattract/request.rb
48
+ - lib/reattract/resources/app_event.rb
49
+ - lib/reattract/resources/campaign.rb
50
+ - lib/reattract/resources/customer.rb
51
+ - lib/reattract/resources/invite_code.rb
52
+ - lib/reattract/resources/invite_conversion.rb
53
+ - lib/reattract/resources/invite_session.rb
54
+ - lib/reattract/version.rb
55
+ - sig/reattract/api.rbs
56
+ homepage: https://docs.reattract.io
57
+ licenses:
58
+ - MIT
59
+ metadata:
60
+ homepage_uri: https://docs.reattract.io
61
+ source_code_uri: https://github.com/reattract/sdk-platform
62
+ changelog_uri: https://github.com/reattract/sdk-platform
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: 2.3.0
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubygems_version: 3.3.7
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Reattract API client
82
+ test_files: []