viral_loops 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 340e9ec452bf69c95b6eae53845626b9088bfc29feb42edbd6d10a6ad03ab977
4
+ data.tar.gz: 39821c7e94855163befb0f8327186cf61edf8bfb169c85220379c76ca1ce288e
5
+ SHA512:
6
+ metadata.gz: 1b6a1b6e7d456fae50de705337d6fd298e1e3930c53483946250800cc57ed2df8ead977251ef04b32b0c0a09b9a7dc2e40612d5e0ad09f0112f5aab1ce685bd2
7
+ data.tar.gz: 6cf7bc2f41ca5f826c15662043c985e29027c8b320f0c0253bfd1c744944dd38939954d0435bb1b778af9f90a1bd8dec9a70a807e4c82f79a2e44a317ae925e6
@@ -0,0 +1,59 @@
1
+ require 'faraday'
2
+ require 'json'
3
+ require 'rack/utils'
4
+
5
+ module ViralLoops
6
+ class Client
7
+ API_VERSION = 'v3'
8
+
9
+ def initialize(secret_token: ViralLoops.configuration.secret_token)
10
+ @connection ||= Faraday.new(url: ViralLoops.configuration.api_base) do |faraday|
11
+ faraday.headers['Content-Type'] = 'application/json'
12
+ faraday.headers['apiToken'] = secret_token
13
+ faraday.adapter Faraday.default_adapter
14
+ faraday.response :logger if ViralLoops.configuration.debug
15
+ end
16
+ end
17
+
18
+ def get(path, params = {})
19
+ handle_response @connection.get(get_path(path), params)
20
+ end
21
+
22
+ def post(path, body = {})
23
+ handle_response @connection.post(get_path(path), body.to_json)
24
+ end
25
+
26
+ private
27
+
28
+ def get_path(path)
29
+ "/api/#{API_VERSION}/#{path}"
30
+ end
31
+
32
+ def handle_response(response)
33
+ case response.status
34
+ when 200..299 then JSON.parse(response.body)
35
+ else
36
+ status_symbol = Rack::Utils::SYMBOL_TO_STATUS_CODE.key(response.status)
37
+ default_message = Rack::Utils::HTTP_STATUS_CODES[response.status] || "API error"
38
+
39
+ raise ViralLoops::ApiError.new(
40
+ body: response.body.to_s.strip.empty? ? default_message : response.body,
41
+ status: response.status,
42
+ )
43
+ end
44
+ end
45
+ end
46
+
47
+ class ApiError < StandardError
48
+ attr_reader :status, :status_symbol, :body
49
+
50
+ def initialize(status:, body: nil, message: nil)
51
+ @status = status
52
+ @status_symbol = Rack::Utils::SYMBOL_TO_STATUS_CODE.key(status)
53
+ @body = body
54
+
55
+ default_message = Rack::Utils::HTTP_STATUS_CODES[status] || 'API Error'
56
+ super(message || "#{default_message} (#{status})")
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,9 @@
1
+ module ViralLoops
2
+ class Configuration
3
+ attr_accessor :api_base, :campaign_id, :debug, :secret_token
4
+
5
+ def initialize
6
+ @api_base = "https://app.viral-loops.com"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ViralLoops
4
+ module Models
5
+ class Participant
6
+ attr_accessor :referral_code, :new
7
+
8
+ def initialize(referral_code:, new: false)
9
+ @referral_code = referral_code
10
+ @new = new
11
+ end
12
+
13
+ def new? = new
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ViralLoops
4
+ module Models
5
+ end
6
+ end
@@ -0,0 +1,13 @@
1
+ module ViralLoops
2
+ module Resources
3
+ class Participants < Client
4
+ BASE_PATH = "campaign/participant"
5
+
6
+ def create(params)
7
+ response = post(BASE_PATH, params)
8
+
9
+ Models::Participant.new(referral_code: response["referralCode"], new: response["isNew"])
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ViralLoops
4
+ module Resources
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module ViralLoops
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "viral_loops/client"
4
+ require "viral_loops/configuration"
5
+ require "viral_loops/resources"
6
+ require "viral_loops/models"
7
+ require "viral_loops/version"
8
+
9
+ require "viral_loops/resources/participants"
10
+ require "viral_loops/models/participant"
11
+
12
+ module ViralLoops
13
+ class << self
14
+ attr_accessor :configuration
15
+
16
+ def configure
17
+ self.configuration ||= Configuration.new
18
+ yield(configuration)
19
+ end
20
+
21
+ def participants
22
+ @participants ||= Resources::Participants.new
23
+ end
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: viral_loops
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Cairo Noleto
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: faraday
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.14'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '2.14'
26
+ - !ruby/object:Gem::Dependency
27
+ name: rack
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '3.2'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.2'
40
+ - !ruby/object:Gem::Dependency
41
+ name: rspec
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.13'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.13'
54
+ - !ruby/object:Gem::Dependency
55
+ name: webmock
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '3.25'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.25'
68
+ email:
69
+ - hey@caironoleto.dev
70
+ executables: []
71
+ extensions: []
72
+ extra_rdoc_files: []
73
+ files:
74
+ - lib/viral_loops.rb
75
+ - lib/viral_loops/client.rb
76
+ - lib/viral_loops/configuration.rb
77
+ - lib/viral_loops/models.rb
78
+ - lib/viral_loops/models/participant.rb
79
+ - lib/viral_loops/resources.rb
80
+ - lib/viral_loops/resources/participants.rb
81
+ - lib/viral_loops/version.rb
82
+ homepage: https://github.com/caironoleto/viral-loops
83
+ licenses:
84
+ - MIT
85
+ metadata: {}
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '3.0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubygems_version: 3.7.2
101
+ specification_version: 4
102
+ summary: Ruby client for the Viral Loops API
103
+ test_files: []