sendgrid-threads 0.1.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 +7 -0
- data/.codeclimate.yml +14 -0
- data/.document +5 -0
- data/.rspec +1 -0
- data/.rubocop.yml +1171 -0
- data/.travis.yml +8 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +117 -0
- data/LICENSE.txt +20 -0
- data/README.md +66 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/lib/sendgrid-threads.rb +13 -0
- data/lib/sendgrid_threads/api.rb +35 -0
- data/lib/sendgrid_threads/client.rb +51 -0
- data/lib/sendgrid_threads/config.rb +21 -0
- data/lib/sendgrid_threads/engine.rb +5 -0
- data/lib/sendgrid_threads/exceptions.rb +7 -0
- data/sendgrid-threads.gemspec +89 -0
- data/spec/sendgrid-threads_spec.rb +7 -0
- data/spec/sendgrid_threads/api_spec.rb +66 -0
- data/spec/sendgrid_threads/client_spec.rb +49 -0
- data/spec/spec_helper.rb +36 -0
- metadata +207 -0
    
        data/.travis.yml
    ADDED
    
    
    
        data/Gemfile
    ADDED
    
    | @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            source "http://rubygems.org"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            group :development, :test do
         | 
| 4 | 
            +
              gem 'activesupport', "~> 4.0"
         | 
| 5 | 
            +
              gem "rspec", "~> 3.0"
         | 
| 6 | 
            +
              gem "rdoc", "~> 4.2"
         | 
| 7 | 
            +
              gem "bundler", "~> 1.10"
         | 
| 8 | 
            +
              gem "jeweler", "~> 2.0.1"
         | 
| 9 | 
            +
              gem "simplecov"
         | 
| 10 | 
            +
              gem "pry-byebug"
         | 
| 11 | 
            +
              gem "webmock"
         | 
| 12 | 
            +
              gem "timecop"
         | 
| 13 | 
            +
              gem "codeclimate-test-reporter", require: nil
         | 
| 14 | 
            +
            end
         | 
    
        data/Gemfile.lock
    ADDED
    
    | @@ -0,0 +1,117 @@ | |
| 1 | 
            +
            GEM
         | 
| 2 | 
            +
              remote: http://rubygems.org/
         | 
| 3 | 
            +
              specs:
         | 
| 4 | 
            +
                activesupport (4.2.5)
         | 
| 5 | 
            +
                  i18n (~> 0.7)
         | 
| 6 | 
            +
                  json (~> 1.7, >= 1.7.7)
         | 
| 7 | 
            +
                  minitest (~> 5.1)
         | 
| 8 | 
            +
                  thread_safe (~> 0.3, >= 0.3.4)
         | 
| 9 | 
            +
                  tzinfo (~> 1.1)
         | 
| 10 | 
            +
                addressable (2.3.8)
         | 
| 11 | 
            +
                builder (3.2.2)
         | 
| 12 | 
            +
                byebug (8.2.1)
         | 
| 13 | 
            +
                codeclimate-test-reporter (0.4.8)
         | 
| 14 | 
            +
                  simplecov (>= 0.7.1, < 1.0.0)
         | 
| 15 | 
            +
                coderay (1.1.0)
         | 
| 16 | 
            +
                crack (0.4.2)
         | 
| 17 | 
            +
                  safe_yaml (~> 1.0.0)
         | 
| 18 | 
            +
                descendants_tracker (0.0.4)
         | 
| 19 | 
            +
                  thread_safe (~> 0.3, >= 0.3.1)
         | 
| 20 | 
            +
                diff-lcs (1.2.5)
         | 
| 21 | 
            +
                docile (1.1.5)
         | 
| 22 | 
            +
                faraday (0.9.2)
         | 
| 23 | 
            +
                  multipart-post (>= 1.2, < 3)
         | 
| 24 | 
            +
                git (1.2.9.1)
         | 
| 25 | 
            +
                github_api (0.13.0)
         | 
| 26 | 
            +
                  addressable (~> 2.3)
         | 
| 27 | 
            +
                  descendants_tracker (~> 0.0.4)
         | 
| 28 | 
            +
                  faraday (~> 0.8, < 0.10)
         | 
| 29 | 
            +
                  hashie (>= 3.4)
         | 
| 30 | 
            +
                  multi_json (>= 1.7.5, < 2.0)
         | 
| 31 | 
            +
                  nokogiri (~> 1.6.6)
         | 
| 32 | 
            +
                  oauth2
         | 
| 33 | 
            +
                hashdiff (0.2.3)
         | 
| 34 | 
            +
                hashie (3.4.3)
         | 
| 35 | 
            +
                highline (1.7.8)
         | 
| 36 | 
            +
                i18n (0.7.0)
         | 
| 37 | 
            +
                jeweler (2.0.1)
         | 
| 38 | 
            +
                  builder
         | 
| 39 | 
            +
                  bundler (>= 1.0)
         | 
| 40 | 
            +
                  git (>= 1.2.5)
         | 
| 41 | 
            +
                  github_api
         | 
| 42 | 
            +
                  highline (>= 1.6.15)
         | 
| 43 | 
            +
                  nokogiri (>= 1.5.10)
         | 
| 44 | 
            +
                  rake
         | 
| 45 | 
            +
                  rdoc
         | 
| 46 | 
            +
                json (1.8.3)
         | 
| 47 | 
            +
                jwt (1.5.2)
         | 
| 48 | 
            +
                method_source (0.8.2)
         | 
| 49 | 
            +
                mini_portile (0.6.2)
         | 
| 50 | 
            +
                minitest (5.8.3)
         | 
| 51 | 
            +
                multi_json (1.11.2)
         | 
| 52 | 
            +
                multi_xml (0.5.5)
         | 
| 53 | 
            +
                multipart-post (2.0.0)
         | 
| 54 | 
            +
                nokogiri (1.6.6.4)
         | 
| 55 | 
            +
                  mini_portile (~> 0.6.0)
         | 
| 56 | 
            +
                oauth2 (1.0.0)
         | 
| 57 | 
            +
                  faraday (>= 0.8, < 0.10)
         | 
| 58 | 
            +
                  jwt (~> 1.0)
         | 
| 59 | 
            +
                  multi_json (~> 1.3)
         | 
| 60 | 
            +
                  multi_xml (~> 0.5)
         | 
| 61 | 
            +
                  rack (~> 1.2)
         | 
| 62 | 
            +
                pry (0.10.3)
         | 
| 63 | 
            +
                  coderay (~> 1.1.0)
         | 
| 64 | 
            +
                  method_source (~> 0.8.1)
         | 
| 65 | 
            +
                  slop (~> 3.4)
         | 
| 66 | 
            +
                pry-byebug (3.3.0)
         | 
| 67 | 
            +
                  byebug (~> 8.0)
         | 
| 68 | 
            +
                  pry (~> 0.10)
         | 
| 69 | 
            +
                rack (1.6.4)
         | 
| 70 | 
            +
                rake (10.4.2)
         | 
| 71 | 
            +
                rdoc (4.2.0)
         | 
| 72 | 
            +
                rspec (3.4.0)
         | 
| 73 | 
            +
                  rspec-core (~> 3.4.0)
         | 
| 74 | 
            +
                  rspec-expectations (~> 3.4.0)
         | 
| 75 | 
            +
                  rspec-mocks (~> 3.4.0)
         | 
| 76 | 
            +
                rspec-core (3.4.1)
         | 
| 77 | 
            +
                  rspec-support (~> 3.4.0)
         | 
| 78 | 
            +
                rspec-expectations (3.4.0)
         | 
| 79 | 
            +
                  diff-lcs (>= 1.2.0, < 2.0)
         | 
| 80 | 
            +
                  rspec-support (~> 3.4.0)
         | 
| 81 | 
            +
                rspec-mocks (3.4.0)
         | 
| 82 | 
            +
                  diff-lcs (>= 1.2.0, < 2.0)
         | 
| 83 | 
            +
                  rspec-support (~> 3.4.0)
         | 
| 84 | 
            +
                rspec-support (3.4.1)
         | 
| 85 | 
            +
                safe_yaml (1.0.4)
         | 
| 86 | 
            +
                simplecov (0.10.0)
         | 
| 87 | 
            +
                  docile (~> 1.1.0)
         | 
| 88 | 
            +
                  json (~> 1.8)
         | 
| 89 | 
            +
                  simplecov-html (~> 0.10.0)
         | 
| 90 | 
            +
                simplecov-html (0.10.0)
         | 
| 91 | 
            +
                slop (3.6.0)
         | 
| 92 | 
            +
                thread_safe (0.3.5)
         | 
| 93 | 
            +
                timecop (0.8.0)
         | 
| 94 | 
            +
                tzinfo (1.2.2)
         | 
| 95 | 
            +
                  thread_safe (~> 0.1)
         | 
| 96 | 
            +
                webmock (1.22.3)
         | 
| 97 | 
            +
                  addressable (>= 2.3.6)
         | 
| 98 | 
            +
                  crack (>= 0.3.2)
         | 
| 99 | 
            +
                  hashdiff
         | 
| 100 | 
            +
             | 
| 101 | 
            +
            PLATFORMS
         | 
| 102 | 
            +
              ruby
         | 
| 103 | 
            +
             | 
| 104 | 
            +
            DEPENDENCIES
         | 
| 105 | 
            +
              activesupport (~> 4.0)
         | 
| 106 | 
            +
              bundler (~> 1.10)
         | 
| 107 | 
            +
              codeclimate-test-reporter
         | 
| 108 | 
            +
              jeweler (~> 2.0.1)
         | 
| 109 | 
            +
              pry-byebug
         | 
| 110 | 
            +
              rdoc (~> 4.2)
         | 
| 111 | 
            +
              rspec (~> 3.0)
         | 
| 112 | 
            +
              simplecov
         | 
| 113 | 
            +
              timecop
         | 
| 114 | 
            +
              webmock
         | 
| 115 | 
            +
             | 
| 116 | 
            +
            BUNDLED WITH
         | 
| 117 | 
            +
               1.10.6
         | 
    
        data/LICENSE.txt
    ADDED
    
    | @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            Copyright (c) 2015 David Paluy
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Permission is hereby granted, free of charge, to any person obtaining
         | 
| 4 | 
            +
            a copy of this software and associated documentation files (the
         | 
| 5 | 
            +
            "Software"), to deal in the Software without restriction, including
         | 
| 6 | 
            +
            without limitation the rights to use, copy, modify, merge, publish,
         | 
| 7 | 
            +
            distribute, sublicense, and/or sell copies of the Software, and to
         | 
| 8 | 
            +
            permit persons to whom the Software is furnished to do so, subject to
         | 
| 9 | 
            +
            the following conditions:
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            The above copyright notice and this permission notice shall be
         | 
| 12 | 
            +
            included in all copies or substantial portions of the Software.
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
         | 
| 15 | 
            +
            EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
         | 
| 16 | 
            +
            MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
         | 
| 17 | 
            +
            NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
         | 
| 18 | 
            +
            LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
         | 
| 19 | 
            +
            OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
         | 
| 20 | 
            +
            WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         | 
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,66 @@ | |
| 1 | 
            +
            # Sendgrid Threads
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Ruby Gem for the SendGrid Threads API https://threads.io/
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            This Gem allows you to send Threads events using native Ruby. For more details, read: https://docs.threads.io/
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            ## Status
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            [](http://badge.fury.io/rb/sendgrid-threads)
         | 
| 10 | 
            +
            [](http://travis-ci.org/dpaluy/sendgrid-threads)
         | 
| 11 | 
            +
            [](https://codeclimate.com/github/dpaluy/sendgrid-threads)
         | 
| 12 | 
            +
            [](https://gemnasium.com/dpaluy/sendgrid-threads)
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            ## Installation
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            Add this line to your application's Gemfile:
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            `gem 'sendgrid-threads'`
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            And then execute:
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            `$ bundle`
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            Or install it yourself using:
         | 
| 25 | 
            +
             | 
| 26 | 
            +
            `$ gem install sendgrid-threads`
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            ## Usage
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            ```
         | 
| 31 | 
            +
            # config/initializers/sendgrid_threads.rb
         | 
| 32 | 
            +
            SendgridThreads.configure do |config|
         | 
| 33 | 
            +
              config.key = 'my_api_key'
         | 
| 34 | 
            +
            end
         | 
| 35 | 
            +
            ```
         | 
| 36 | 
            +
             | 
| 37 | 
            +
            ```
         | 
| 38 | 
            +
            api = SendgridThreads::Api.new
         | 
| 39 | 
            +
             | 
| 40 | 
            +
            # identify user
         | 
| 41 | 
            +
            api.identify("unique_user_id", {email: "user@example.com", other: "parameters"})
         | 
| 42 | 
            +
             | 
| 43 | 
            +
            # track event
         | 
| 44 | 
            +
            api.track("unique_user_id", "Event name", {any: "custom", user: "properties"})
         | 
| 45 | 
            +
             | 
| 46 | 
            +
            # track page view
         | 
| 47 | 
            +
            api.page_view("unique_user_id", "Page name", {any: "custom", user: "properties"})
         | 
| 48 | 
            +
             | 
| 49 | 
            +
            # remove user
         | 
| 50 | 
            +
            api.remove("unique_user_id")
         | 
| 51 | 
            +
             | 
| 52 | 
            +
            ```
         | 
| 53 | 
            +
             | 
| 54 | 
            +
            ## Contributing to sendgrid-threads
         | 
| 55 | 
            +
             | 
| 56 | 
            +
            * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
         | 
| 57 | 
            +
            * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
         | 
| 58 | 
            +
            * Fork the project.
         | 
| 59 | 
            +
            * Start a feature/bugfix branch.
         | 
| 60 | 
            +
            * Commit and push until you are happy with your contribution.
         | 
| 61 | 
            +
            * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
         | 
| 62 | 
            +
            * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
         | 
| 63 | 
            +
             | 
| 64 | 
            +
            ## Copyright
         | 
| 65 | 
            +
             | 
| 66 | 
            +
            Copyright (c) 2015 David Paluy. See LICENSE.txt for further details.
         | 
    
        data/Rakefile
    ADDED
    
    | @@ -0,0 +1,50 @@ | |
| 1 | 
            +
            # encoding: utf-8
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'rubygems'
         | 
| 4 | 
            +
            require 'bundler'
         | 
| 5 | 
            +
            begin
         | 
| 6 | 
            +
              Bundler.setup(:default, :development)
         | 
| 7 | 
            +
            rescue Bundler::BundlerError => e
         | 
| 8 | 
            +
              $stderr.puts e.message
         | 
| 9 | 
            +
              $stderr.puts "Run `bundle install` to install missing gems"
         | 
| 10 | 
            +
              exit e.status_code
         | 
| 11 | 
            +
            end
         | 
| 12 | 
            +
            require 'rake'
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            require 'jeweler'
         | 
| 15 | 
            +
            Jeweler::Tasks.new do |gem|
         | 
| 16 | 
            +
              # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
         | 
| 17 | 
            +
              gem.name = "sendgrid-threads"
         | 
| 18 | 
            +
              gem.homepage = "http://github.com/dpaluy/sendgrid-threads"
         | 
| 19 | 
            +
              gem.license = "MIT"
         | 
| 20 | 
            +
              gem.summary = %Q{Ruby Gem for the SendGrid Threads API https://threads.io/ }
         | 
| 21 | 
            +
              gem.description = %Q{This Gem allows you to send Threads events using native Ruby https://docs.threads.io/}
         | 
| 22 | 
            +
              gem.email = "dpaluy@gmail.com"
         | 
| 23 | 
            +
              gem.authors = ["David Paluy"]
         | 
| 24 | 
            +
              # dependencies defined in Gemfile
         | 
| 25 | 
            +
            end
         | 
| 26 | 
            +
            Jeweler::RubygemsDotOrgTasks.new
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            require 'rspec/core'
         | 
| 29 | 
            +
            require 'rspec/core/rake_task'
         | 
| 30 | 
            +
            RSpec::Core::RakeTask.new(:spec) do |spec|
         | 
| 31 | 
            +
              spec.pattern = FileList['spec/**/*_spec.rb']
         | 
| 32 | 
            +
            end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            desc "Code coverage detail"
         | 
| 35 | 
            +
            task :simplecov do
         | 
| 36 | 
            +
              ENV['COVERAGE'] = "true"
         | 
| 37 | 
            +
              Rake::Task['spec'].execute
         | 
| 38 | 
            +
            end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
            task :default => :spec
         | 
| 41 | 
            +
             | 
| 42 | 
            +
            require 'rdoc/task'
         | 
| 43 | 
            +
            Rake::RDocTask.new do |rdoc|
         | 
| 44 | 
            +
              version = File.exist?('VERSION') ? File.read('VERSION') : ""
         | 
| 45 | 
            +
             | 
| 46 | 
            +
              rdoc.rdoc_dir = 'rdoc'
         | 
| 47 | 
            +
              rdoc.title = "sendgrid-threads #{version}"
         | 
| 48 | 
            +
              rdoc.rdoc_files.include('README*')
         | 
| 49 | 
            +
              rdoc.rdoc_files.include('lib/**/*.rb')
         | 
| 50 | 
            +
            end
         | 
    
        data/VERSION
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            0.1.0
         | 
| @@ -0,0 +1,13 @@ | |
| 1 | 
            +
            require_relative 'sendgrid_threads/config'
         | 
| 2 | 
            +
            require_relative 'sendgrid_threads/exceptions'
         | 
| 3 | 
            +
            require_relative 'sendgrid_threads/client'
         | 
| 4 | 
            +
            require_relative 'sendgrid_threads/api'
         | 
| 5 | 
            +
            require_relative 'sendgrid_threads/engine' if defined?(Rails)
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            module SendgridThreads
         | 
| 8 | 
            +
              VERSION = File.read(File.expand_path('../../VERSION', __FILE__)).strip.freeze
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              def self.logger
         | 
| 11 | 
            +
                config.logger
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
            end
         | 
| @@ -0,0 +1,35 @@ | |
| 1 | 
            +
            module SendgridThreads
         | 
| 2 | 
            +
              class Api
         | 
| 3 | 
            +
                attr_reader :connection
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                def initialize( params = {} )
         | 
| 6 | 
            +
                  @connection = SendgridThreads::Client.new(params)
         | 
| 7 | 
            +
                end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                def identify(user_id, traits = {}, timestamp = Time.now )
         | 
| 10 | 
            +
                  body = {userId: user_id, traits: traits, timestamp: utc_iso8601(timestamp)}
         | 
| 11 | 
            +
                  @connection.post("identify", body)
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                def track(user_id, event, properties = {}, timestamp = Time.now)
         | 
| 15 | 
            +
                  body = {userId: user_id, event: event, timestamp: utc_iso8601(timestamp), properties: properties}
         | 
| 16 | 
            +
                  @connection.post("track", body)
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                def page_view(user_id, name, properties = {}, timestamp = Time.now)
         | 
| 20 | 
            +
                  body = {userId: user_id, name: name, timestamp: utc_iso8601(timestamp), properties: properties}
         | 
| 21 | 
            +
                  @connection.post("page", body)
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                def remove(user_id, timestamp = Time.now)
         | 
| 25 | 
            +
                  body = {userId: user_id, timestamp: utc_iso8601(timestamp)}
         | 
| 26 | 
            +
                  @connection.post("remove", body)
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                private
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                def utc_iso8601(timestamp)
         | 
| 32 | 
            +
                  timestamp.utc.iso8601.gsub(/Z$/, '.000Z')
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
              end
         | 
| 35 | 
            +
            end
         | 
| @@ -0,0 +1,51 @@ | |
| 1 | 
            +
            require 'faraday'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module SendgridThreads
         | 
| 4 | 
            +
              class Client
         | 
| 5 | 
            +
                VERSION = "v1".freeze
         | 
| 6 | 
            +
                URL     = 'https://input.threads.io'.freeze
         | 
| 7 | 
            +
                HEADERS = {'Content-Type' => 'application/json', 'Accept' => 'application/json'}.freeze
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                attr_reader :key, :secret, :url, :user_agent, :raise_exceptions
         | 
| 10 | 
            +
                attr_writer :adapter, :conn
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                def initialize( params = {} )
         | 
| 13 | 
            +
                  @key    = params.fetch(:key,    SendgridThreads.config.key)
         | 
| 14 | 
            +
                  @secret = params.fetch(:secret, SendgridThreads.config.secret)
         | 
| 15 | 
            +
                  @url    = params.fetch(:url,    SendgridThreads.config.url || URL)
         | 
| 16 | 
            +
                  @raise_exceptions = params.fetch(:raise_exceptions,
         | 
| 17 | 
            +
                                            SendgridThreads.config.raise_exceptions || true)
         | 
| 18 | 
            +
                  @adapter    = params.fetch(:adapter, adapter)
         | 
| 19 | 
            +
                  @conn       = params.fetch(:conn, conn)
         | 
| 20 | 
            +
                  @user_agent = params.fetch(:user_agent, "sendgrid-threads/#{SendgridThreads::VERSION};ruby")
         | 
| 21 | 
            +
                  yield self if block_given?
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                def post(endpoint, body = nil)
         | 
| 25 | 
            +
                  endpoint_with_version = "/#{VERSION}/#{endpoint}"
         | 
| 26 | 
            +
                  response = conn.post(endpoint_with_version) do |req|
         | 
| 27 | 
            +
                    req.headers = HEADERS.merge('User-Agent' => @user_agent)
         | 
| 28 | 
            +
                    req.body = JSON(body) if body
         | 
| 29 | 
            +
                  end
         | 
| 30 | 
            +
                  fail SendgridThreads::Exception, response.body if raise_exceptions? && response.status != 200
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                  response
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                def conn
         | 
| 36 | 
            +
                  @conn ||= Faraday.new(url: @url) do |conn|
         | 
| 37 | 
            +
                    conn.request :url_encoded
         | 
| 38 | 
            +
                    conn.request :basic_auth, @key, @secret
         | 
| 39 | 
            +
                    conn.adapter adapter
         | 
| 40 | 
            +
                  end
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                def adapter
         | 
| 44 | 
            +
                  @adapter ||= Faraday.default_adapter
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                def raise_exceptions?
         | 
| 48 | 
            +
                  @raise_exceptions
         | 
| 49 | 
            +
                end
         | 
| 50 | 
            +
              end
         | 
| 51 | 
            +
            end
         | 
| @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            require 'logger'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module SendgridThreads
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              class Config
         | 
| 6 | 
            +
                attr_accessor :key, :secret, :url, :logger, :raise_exceptions
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                def logger
         | 
| 9 | 
            +
                  @logger ||= Logger.new(STDERR)
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
              end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              def self.configure
         | 
| 14 | 
            +
                yield config
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              def self.config
         | 
| 18 | 
            +
                @config ||= Config.new
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            end
         | 
| @@ -0,0 +1,89 @@ | |
| 1 | 
            +
            # Generated by jeweler
         | 
| 2 | 
            +
            # DO NOT EDIT THIS FILE DIRECTLY
         | 
| 3 | 
            +
            # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
         | 
| 4 | 
            +
            # -*- encoding: utf-8 -*-
         | 
| 5 | 
            +
            # stub: sendgrid-threads 0.1.0 ruby lib
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            Gem::Specification.new do |s|
         | 
| 8 | 
            +
              s.name = "sendgrid-threads"
         | 
| 9 | 
            +
              s.version = "0.1.0"
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         | 
| 12 | 
            +
              s.require_paths = ["lib"]
         | 
| 13 | 
            +
              s.authors = ["David Paluy"]
         | 
| 14 | 
            +
              s.date = "2015-11-28"
         | 
| 15 | 
            +
              s.description = "This Gem allows you to send Threads events using native Ruby https://docs.threads.io/"
         | 
| 16 | 
            +
              s.email = "dpaluy@gmail.com"
         | 
| 17 | 
            +
              s.extra_rdoc_files = [
         | 
| 18 | 
            +
                "LICENSE.txt",
         | 
| 19 | 
            +
                "README.md"
         | 
| 20 | 
            +
              ]
         | 
| 21 | 
            +
              s.files = [
         | 
| 22 | 
            +
                ".codeclimate.yml",
         | 
| 23 | 
            +
                ".document",
         | 
| 24 | 
            +
                ".rspec",
         | 
| 25 | 
            +
                ".rubocop.yml",
         | 
| 26 | 
            +
                ".travis.yml",
         | 
| 27 | 
            +
                "Gemfile",
         | 
| 28 | 
            +
                "Gemfile.lock",
         | 
| 29 | 
            +
                "LICENSE.txt",
         | 
| 30 | 
            +
                "README.md",
         | 
| 31 | 
            +
                "Rakefile",
         | 
| 32 | 
            +
                "VERSION",
         | 
| 33 | 
            +
                "lib/sendgrid-threads.rb",
         | 
| 34 | 
            +
                "lib/sendgrid_threads/api.rb",
         | 
| 35 | 
            +
                "lib/sendgrid_threads/client.rb",
         | 
| 36 | 
            +
                "lib/sendgrid_threads/config.rb",
         | 
| 37 | 
            +
                "lib/sendgrid_threads/engine.rb",
         | 
| 38 | 
            +
                "lib/sendgrid_threads/exceptions.rb",
         | 
| 39 | 
            +
                "sendgrid-threads.gemspec",
         | 
| 40 | 
            +
                "spec/sendgrid-threads_spec.rb",
         | 
| 41 | 
            +
                "spec/sendgrid_threads/api_spec.rb",
         | 
| 42 | 
            +
                "spec/sendgrid_threads/client_spec.rb",
         | 
| 43 | 
            +
                "spec/spec_helper.rb"
         | 
| 44 | 
            +
              ]
         | 
| 45 | 
            +
              s.homepage = "http://github.com/dpaluy/sendgrid-threads"
         | 
| 46 | 
            +
              s.licenses = ["MIT"]
         | 
| 47 | 
            +
              s.rubygems_version = "2.4.5.1"
         | 
| 48 | 
            +
              s.summary = "Ruby Gem for the SendGrid Threads API https://threads.io/"
         | 
| 49 | 
            +
             | 
| 50 | 
            +
              if s.respond_to? :specification_version then
         | 
| 51 | 
            +
                s.specification_version = 4
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
         | 
| 54 | 
            +
                  s.add_development_dependency(%q<activesupport>, ["~> 4.0"])
         | 
| 55 | 
            +
                  s.add_development_dependency(%q<rspec>, ["~> 3.0"])
         | 
| 56 | 
            +
                  s.add_development_dependency(%q<rdoc>, ["~> 4.2"])
         | 
| 57 | 
            +
                  s.add_development_dependency(%q<bundler>, ["~> 1.10"])
         | 
| 58 | 
            +
                  s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
         | 
| 59 | 
            +
                  s.add_development_dependency(%q<simplecov>, [">= 0"])
         | 
| 60 | 
            +
                  s.add_development_dependency(%q<pry-byebug>, [">= 0"])
         | 
| 61 | 
            +
                  s.add_development_dependency(%q<webmock>, [">= 0"])
         | 
| 62 | 
            +
                  s.add_development_dependency(%q<timecop>, [">= 0"])
         | 
| 63 | 
            +
                  s.add_development_dependency(%q<codeclimate-test-reporter>, [">= 0"])
         | 
| 64 | 
            +
                else
         | 
| 65 | 
            +
                  s.add_dependency(%q<activesupport>, ["~> 4.0"])
         | 
| 66 | 
            +
                  s.add_dependency(%q<rspec>, ["~> 3.0"])
         | 
| 67 | 
            +
                  s.add_dependency(%q<rdoc>, ["~> 4.2"])
         | 
| 68 | 
            +
                  s.add_dependency(%q<bundler>, ["~> 1.10"])
         | 
| 69 | 
            +
                  s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
         | 
| 70 | 
            +
                  s.add_dependency(%q<simplecov>, [">= 0"])
         | 
| 71 | 
            +
                  s.add_dependency(%q<pry-byebug>, [">= 0"])
         | 
| 72 | 
            +
                  s.add_dependency(%q<webmock>, [">= 0"])
         | 
| 73 | 
            +
                  s.add_dependency(%q<timecop>, [">= 0"])
         | 
| 74 | 
            +
                  s.add_dependency(%q<codeclimate-test-reporter>, [">= 0"])
         | 
| 75 | 
            +
                end
         | 
| 76 | 
            +
              else
         | 
| 77 | 
            +
                s.add_dependency(%q<activesupport>, ["~> 4.0"])
         | 
| 78 | 
            +
                s.add_dependency(%q<rspec>, ["~> 3.0"])
         | 
| 79 | 
            +
                s.add_dependency(%q<rdoc>, ["~> 4.2"])
         | 
| 80 | 
            +
                s.add_dependency(%q<bundler>, ["~> 1.10"])
         | 
| 81 | 
            +
                s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
         | 
| 82 | 
            +
                s.add_dependency(%q<simplecov>, [">= 0"])
         | 
| 83 | 
            +
                s.add_dependency(%q<pry-byebug>, [">= 0"])
         | 
| 84 | 
            +
                s.add_dependency(%q<webmock>, [">= 0"])
         | 
| 85 | 
            +
                s.add_dependency(%q<timecop>, [">= 0"])
         | 
| 86 | 
            +
                s.add_dependency(%q<codeclimate-test-reporter>, [">= 0"])
         | 
| 87 | 
            +
              end
         | 
| 88 | 
            +
            end
         | 
| 89 | 
            +
             |