loops_rails 0.1.0

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: be0f5a041a6bc29955f19f4f9f81ecb670233e2a8776772d8e894070eab38a6a
4
+ data.tar.gz: a6b3358e15f6b3dcf6db27999205c7ee6066ed08e9034840c20db4d51e106430
5
+ SHA512:
6
+ metadata.gz: 87d31d93f2c08cd5305e533b18b5b0c295f40cdf478194e308189e87ea2d45964d41c21a93f75aed853a12e1f32d8c65a83539f1aa56c157b92cb533cc21c51f
7
+ data.tar.gz: 005f4aa20127104f6b35070b205a8ace43de454e225e4cbe86117b675abc4db6fcdd9b390fef0447e34cfc2c273d12ef0d3917b28e8fb472469ac7e0e4089c0f
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Daniel Friis
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
+ # LoopsRails
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/loops_rails`. 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 test` 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]/loops_rails.
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,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ require "rubocop/rake_task"
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[test rubocop]
@@ -0,0 +1,8 @@
1
+ module LoopsRails
2
+ class ApiKey < ApiResource
3
+ def test_api_key
4
+ response = @conn.get('api-key')
5
+ parse_response(response)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,15 @@
1
+ module LoopsRails
2
+ class ApiResource
3
+ def initialize(conn)
4
+ @conn = conn
5
+ end
6
+
7
+ private
8
+
9
+ def parse_response(response)
10
+ JSON.parse(response.body)
11
+ rescue JSON::ParserError
12
+ response.body
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,45 @@
1
+ module LoopsRails
2
+ class Contacts < ApiResource
3
+ def create(email:, **attributes)
4
+ payload = { email: email }.merge(attributes).compact
5
+
6
+ response = @conn.post("contacts/create") do |req|
7
+ req.body = payload.to_json
8
+ end
9
+
10
+ parse_response(response)
11
+ end
12
+
13
+ def update(email:, **attributes)
14
+ payload = { email: email }.merge(attributes).compact
15
+
16
+ response = @conn.put("contacts/update") do |req|
17
+ req.body = payload.to_json
18
+ end
19
+
20
+ parse_response(response)
21
+ end
22
+
23
+ def find(email: nil, user_id: nil)
24
+ raise ArgumentError, "Either email or user_id must be provided" if email.nil? && user_id.nil?
25
+
26
+ params = { email: email, userId: user_id }.compact
27
+ response = @conn.get("contacts/find") do |req|
28
+ req.params = params
29
+ end
30
+ parse_response(response)
31
+ end
32
+
33
+ def delete(email: nil, user_id: nil)
34
+ raise ArgumentError, "Either email or user_id must be provided" if email.nil? && user_id.nil?
35
+
36
+ payload = { email: email, userId: user_id }.compact
37
+
38
+ response = @conn.post("contacts/delete") do |req|
39
+ req.body = payload.to_json
40
+ end
41
+
42
+ parse_response(response)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,15 @@
1
+ module LoopsRails
2
+ class TransactionalEmails < ApiResource
3
+ def send(email:, transactional_id:, data_variables: {}, attachments: [])
4
+ response = @conn.post('transactional') do |req|
5
+ req.body = {
6
+ email: email,
7
+ transactionalId: transactional_id,
8
+ dataVariables: data_variables,
9
+ attachments: attachments
10
+ }.to_json
11
+ end
12
+ parse_response(response)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,27 @@
1
+ module LoopsRails
2
+ class Client
3
+ BASE_URL = 'https://app.loops.so/api/v1/'
4
+
5
+ def initialize(api_key = LoopsRails.configuration.api_key)
6
+ @api_key = api_key
7
+ @conn = Faraday.new(url: BASE_URL) do |faraday|
8
+ faraday.request :url_encoded
9
+ faraday.adapter Faraday.default_adapter
10
+ faraday.headers['Authorization'] = "Bearer #{@api_key}"
11
+ faraday.headers['Content-Type'] = 'application/json'
12
+ end
13
+ end
14
+
15
+ def api_key
16
+ @api_key ||= ApiKey.new(@conn)
17
+ end
18
+
19
+ def contacts
20
+ @contacts ||= Contacts.new(@conn)
21
+ end
22
+
23
+ def transactional_emails
24
+ @transactional_emails ||= TransactionalEmails.new(@conn)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,14 @@
1
+ module LoopsRails
2
+ class Configuration
3
+ attr_accessor :api_key
4
+ end
5
+
6
+ def self.configuration
7
+ @configuration ||= Configuration.new
8
+ end
9
+
10
+ def self.configure
11
+ yield(configuration)
12
+ end
13
+ end
14
+
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LoopsRails
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'json'
5
+ require_relative "loops_rails/version"
6
+ require_relative "loops_rails/client"
7
+ require_relative "loops_rails/configuration"
8
+ require_relative "loops_rails/client/api_resource"
9
+ require_relative "loops_rails/client/api_key"
10
+ require_relative "loops_rails/client/contacts"
11
+ require_relative "loops_rails/client/transactional_emails"
12
+
13
+ module LoopsRails
14
+ class Error < StandardError; end
15
+
16
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/loops_rails/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "loops_rails"
7
+ spec.version = LoopsRails::VERSION
8
+ spec.authors = ["Daniel Friis"]
9
+ spec.email = ["d@friis.me"]
10
+
11
+ spec.summary = "Rails integration for Loops"
12
+ spec.description = "Rails integration for Loops"
13
+ spec.homepage = "https://github.com/danielfriis/loops_rails"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = spec.homepage
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(__dir__) do
25
+ `git ls-files -z`.split("\x0").reject do |f|
26
+ (File.expand_path(f) == __FILE__) ||
27
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git appveyor Gemfile])
28
+ end
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ # Uncomment to register a new dependency of your gem
35
+ spec.add_dependency "faraday"
36
+
37
+ # For more information and examples about making a new gem, check out our
38
+ # guide at: https://bundler.io/guides/creating_gem.html
39
+ end
@@ -0,0 +1,4 @@
1
+ module LoopsRails
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: loops_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Friis
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-07-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
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
+ description: Rails integration for Loops
28
+ email:
29
+ - d@friis.me
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rubocop.yml"
35
+ - LICENSE.txt
36
+ - README.md
37
+ - Rakefile
38
+ - lib/loops_rails.rb
39
+ - lib/loops_rails/client.rb
40
+ - lib/loops_rails/client/api_key.rb
41
+ - lib/loops_rails/client/api_resource.rb
42
+ - lib/loops_rails/client/contacts.rb
43
+ - lib/loops_rails/client/transactional_emails.rb
44
+ - lib/loops_rails/configuration.rb
45
+ - lib/loops_rails/version.rb
46
+ - loops_rails.gemspec
47
+ - sig/loops_rails.rbs
48
+ homepage: https://github.com/danielfriis/loops_rails
49
+ licenses:
50
+ - MIT
51
+ metadata:
52
+ allowed_push_host: https://rubygems.org
53
+ homepage_uri: https://github.com/danielfriis/loops_rails
54
+ source_code_uri: https://github.com/danielfriis/loops_rails
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 2.6.0
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubygems_version: 3.4.22
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: Rails integration for Loops
74
+ test_files: []