whatconverts 0.1.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
+ SHA1:
3
+ metadata.gz: a97a59bb1e26bf1762a4e35de2210d714e4843a3
4
+ data.tar.gz: 2e72e56d0557ba2e0bc9852a50331db15e59e8d8
5
+ SHA512:
6
+ metadata.gz: d29baea75f5c055b1ce5dc583fde85ba67155bd3011322f3188b327d8f158563d2e3263ce7ecde37cbe22b21d4b9c8468e345efc765a1f76c214d7e5a3b191dd
7
+ data.tar.gz: fb937628f77d1b2532067584a6a23c9d3184eb12a5ce44ede85831f75b5d2cb7db969ee34c7f4fb7be101f158277fe71db3d8be6673fd5f6ffd92aec85a2a1bf
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.swp
11
+ /examples/
12
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in whatconverts.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Joe Macbook Pro
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,56 @@
1
+ # The WhatConverts Ruby Gem
2
+
3
+ A Ruby interface for the [WhatConverts API](https://whatconverts.com/api).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'whatconverts'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install whatconverts
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ client = Whatconverts::Client.new do |config|
25
+ config.api_token = 'YOUR_API_TOKEN'
26
+ config.api_secret = 'TOUR_API_SECRET'
27
+ end
28
+
29
+ # retrieve leads
30
+ client.leads
31
+
32
+ # retrieve leads with param filtering
33
+ client.leads(lead_type: 'phone_call', lead_status: 'unique')
34
+
35
+ # fetch lead by ID
36
+ client.lead(999)
37
+
38
+ # create new lead
39
+ client.create_lead(
40
+ lead_type: 'Web Form',
41
+ form_name: 'My Form'
42
+ )
43
+
44
+ # edit existing lead
45
+ client.edit_lead(999, lead_source: 'google')
46
+ ```
47
+
48
+ ## Contributing
49
+
50
+ Bug reports and pull requests are welcome on GitHub at https://github.com/neeaagh/whatconverts.
51
+
52
+
53
+ ## License
54
+
55
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
56
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "whatconverts"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,9 @@
1
+ require 'json'
2
+ require 'faraday'
3
+
4
+ require 'whatconverts/version'
5
+ require 'whatconverts/client'
6
+ require 'whatconverts/http_service'
7
+ require 'whatconverts/error_checker'
8
+ require 'whatconverts/errors'
9
+
@@ -0,0 +1,35 @@
1
+ module Whatconverts
2
+ class Client
3
+
4
+ attr_accessor :api_token, :api_secret
5
+
6
+ def initialize
7
+ yield self if block_given?
8
+ end
9
+
10
+ def leads(params = {})
11
+ http_service.make_request('leads', params)
12
+ end
13
+
14
+ def lead(lead_id, params = {})
15
+ http_service.make_request("leads/#{lead_id}", params)
16
+ end
17
+
18
+ def create_lead(params = {})
19
+ params.merge!(method: :post)
20
+ http_service.make_request('leads', params)
21
+ end
22
+
23
+ def edit_lead(lead_id, params = {})
24
+ params.merge!(method: :post)
25
+ http_service.make_request("leads/#{lead_id}", params)
26
+ end
27
+
28
+ private
29
+
30
+ def http_service
31
+ HttpService.new(api_token, api_secret)
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,31 @@
1
+ module Whatconverts
2
+ class ErrorChecker
3
+
4
+ attr_reader :api_response
5
+
6
+ def initialize(api_response)
7
+ @api_response = api_response
8
+ end
9
+
10
+ def error_if_appropriate
11
+ return AuthError.new(response_body) if is_auth_error?
12
+ return ApiError.new(response_body) if is_error?
13
+ end
14
+
15
+ private
16
+
17
+ def is_auth_error?
18
+ api_response.status.to_i == 401
19
+ end
20
+
21
+ def is_error?
22
+ api_response.status.to_i >= 400
23
+ end
24
+
25
+ def response_body
26
+ JSON.parse(api_response.body)['error_message']
27
+ rescue
28
+ api_response.body
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,4 @@
1
+ module Whatconverts
2
+ class ApiError < StandardError; end
3
+ class AuthError < StandardError; end
4
+ end
@@ -0,0 +1,27 @@
1
+ module Whatconverts
2
+ class HttpService
3
+ API_URL = 'https://app.whatconverts.com/api/v1/'.freeze
4
+
5
+ attr_accessor :api_token, :api_secret
6
+
7
+ def initialize(api_token, api_secret)
8
+ @api_token = api_token
9
+ @api_secret = api_secret
10
+ end
11
+
12
+ def make_request(endpoint, params = {})
13
+ method = params.delete(:method) { :get }
14
+ response = connection.send(method, endpoint, params)
15
+ error = ErrorChecker.new(response).error_if_appropriate
16
+ raise error if error
17
+ JSON.parse(response.body)
18
+ end
19
+
20
+ def connection
21
+ conn = Faraday.new(url: API_URL)
22
+ conn.basic_auth(api_token, api_secret)
23
+ conn
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module Whatconverts
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'whatconverts/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "whatconverts"
8
+ spec.version = Whatconverts::VERSION
9
+ spec.authors = ["Joe Giancaspro"]
10
+ spec.email = ["neeaagh@gmail.com"]
11
+
12
+ spec.summary = %q{A Ruby gem for interacting with the WhatConverts API.}
13
+ spec.description = %q{A Ruby gem for interacting with the WhatConverts API.}
14
+ spec.homepage = "https://github.com/neeaagh/whatconverts"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.required_ruby_version = ">= 2.0.0"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.10"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~>3.5"
27
+ spec.add_development_dependency "pry", "~>0.10"
28
+ spec.add_development_dependency "webmock", "2.1"
29
+
30
+ spec.add_dependency "faraday", "~> 0.9"
31
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: whatconverts
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Joe Giancaspro
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-08-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: '2.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: '2.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: faraday
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.9'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.9'
97
+ description: A Ruby gem for interacting with the WhatConverts API.
98
+ email:
99
+ - neeaagh@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - lib/whatconverts.rb
114
+ - lib/whatconverts/client.rb
115
+ - lib/whatconverts/error_checker.rb
116
+ - lib/whatconverts/errors.rb
117
+ - lib/whatconverts/http_service.rb
118
+ - lib/whatconverts/version.rb
119
+ - whatconverts.gemspec
120
+ homepage: https://github.com/neeaagh/whatconverts
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: 2.0.0
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.4.5.1
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: A Ruby gem for interacting with the WhatConverts API.
144
+ test_files: []