get_response 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
+ SHA1:
3
+ metadata.gz: d9da541994de430a3934c8e1c8c2a363b3dc8b71
4
+ data.tar.gz: 6e5e5323026bbfbb115d261f2da828b2deb0ae76
5
+ SHA512:
6
+ metadata.gz: 648f43ce4d0307c7df72fa693067ff70f14d5c696fcef4f530c29c7fb30a74d554eb744171479da23346bd5e2d91f96ceba10387db998d109bae871f38c52e0f
7
+ data.tar.gz: 57511ab167f8f272d782cc9f55b152a9faa30be1821f93cf76daf75862a4a301dd33efa20c5b226c87cb2343697ca60c81f25c64bb46a37936d85cb53fb30616
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .rvmrc
11
+ *.gem
12
+
13
+ # rspec failure tracking
14
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.14.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in getresponse_ruby.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Faizal Zakaria
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,54 @@
1
+ # GetresponseRuby
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'getresponse_ruby'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install getresponse_ruby
18
+
19
+ ## Usage
20
+
21
+ ### To configure
22
+
23
+ ```ruby
24
+ GetResponse.configure do |config|
25
+ config.api_key = 'api key'
26
+ config.api_endpoint = 'http://ello.malaysia.com'
27
+ end
28
+ ```
29
+
30
+ ### To use it
31
+
32
+ ```ruby
33
+ # Get contacts
34
+ api = GetResponse::Api.new
35
+ # Crate contact
36
+ api.contacts.create(params)
37
+ # Get campaigns
38
+ api.campaigns.retrieve
39
+ ```
40
+
41
+ ## Development
42
+
43
+ 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.
44
+
45
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
46
+
47
+ ## Contributing
48
+
49
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kfit-dev/getresponse_ruby.
50
+
51
+ ## License
52
+
53
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
54
+
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 "getresponse_ruby"
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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -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 'get_response/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "get_response"
8
+ spec.version = GetResponse::VERSION
9
+ spec.authors = ["Faizal Zakaria"]
10
+ spec.email = ["phaibusiness@gmail.com"]
11
+
12
+ spec.summary = "Get Response Ruby Library"
13
+ spec.description = "Get Response Ruby Library ..."
14
+ spec.homepage = "https://github.com/kfit-dev/getresponse_ruby"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.14"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "pry", '~> 0.10.4'
28
+ spec.add_development_dependency 'webmock'
29
+ spec.add_runtime_dependency 'json', '~> 1.8.6'
30
+ spec.add_runtime_dependency 'faraday', '~> 0.9.2'
31
+ end
@@ -0,0 +1,22 @@
1
+ require 'faraday'
2
+ require "get_response/version"
3
+ require "get_response/request"
4
+ require "get_response/api"
5
+ require "get_response/response"
6
+
7
+ module GetResponse
8
+ class << self
9
+ def configure
10
+ yield(configuration)
11
+ end
12
+
13
+ def configuration
14
+ @config ||= Config.new
15
+ end
16
+ alias_method :config, :configuration
17
+ end
18
+
19
+ class Config
20
+ attr_accessor :api_key, :verbose, :api_endpoint, :domain_header, :api_version
21
+ end
22
+ end
@@ -0,0 +1,53 @@
1
+ module GetResponse
2
+ class Api
3
+
4
+ def initialize
5
+ @path_parts = []
6
+ end
7
+
8
+ def method_missing(method, *args)
9
+ @path_parts << method.to_s.gsub("_", "-").downcase
10
+ @path_parts << args if args.length > 0
11
+ @path_parts.flatten!
12
+ self
13
+ end
14
+
15
+ def create(params = {})
16
+ resp = GetResponse::Request.post(path, params)
17
+ Response.new(resp)
18
+ ensure
19
+ reset
20
+ end
21
+
22
+ def update(params)
23
+ resp = GetResponse::Request.post(path, params)
24
+ Response.new(resp)
25
+ ensure
26
+ reset
27
+ end
28
+
29
+ def retrieve(params = {})
30
+ resp = GetResponse::Request.get(path, params)
31
+ Response.new(resp)
32
+ ensure
33
+ reset
34
+ end
35
+
36
+ def delete
37
+ resp = GetResponse::Request.delete(path, params)
38
+ Response.new(resp)
39
+ ensure
40
+ reset
41
+ end
42
+
43
+ private
44
+
45
+ def path
46
+ @path_parts.join('/')
47
+ end
48
+
49
+ def reset
50
+ @path_parts = []
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,75 @@
1
+ module GetResponse
2
+ class Request
3
+
4
+ class << self
5
+ DEFAULT_API_ENDPOINT = 'https://api3.getresponse360.com'
6
+ DEFAULT_API_VERSION = 'v3'
7
+
8
+ [:post, :get].each do |method|
9
+ define_method method do |path, params|
10
+ connection.send("#{method}") do |req|
11
+ req.url build_api_path(path)
12
+ req.params = params if method == :get
13
+ req.body = (params || {}).to_json if method == :post
14
+ req.headers = headers
15
+ end
16
+ end
17
+ end
18
+
19
+ # TODO
20
+ def delete
21
+ puts 'delete = todo'
22
+ end
23
+
24
+ private
25
+
26
+ def connection
27
+ @connection ||= Faraday.new(url: api_endpoint) do |faraday|
28
+ faraday.request :url_encoded
29
+ faraday.adapter Faraday.default_adapter
30
+ end
31
+ end
32
+
33
+ def api_endpoint
34
+ GetResponse.config.api_endpoint || DEFAULT_API_ENDPOINT
35
+ end
36
+
37
+ def build_api_path(path)
38
+ "#{api_version}/#{path}"
39
+ end
40
+
41
+ def api_version
42
+ GetResponse.config.api_version || DEFAULT_API_VERSION
43
+ end
44
+
45
+ def headers
46
+ user_agent_header
47
+ .merge(json_header)
48
+ .merge(auth_header)
49
+ .merge(domain_header)
50
+ end
51
+
52
+ def user_agent_header
53
+ { 'User-Agent' => 'GetResponse Ruby SDK' }
54
+ end
55
+
56
+ def json_header
57
+ { 'Content-Type' => 'application/json' }
58
+ end
59
+
60
+ def auth_header
61
+ return {} unless GetResponse.config.api_key
62
+ { 'X-Auth-Token' => "api-key #{GetResponse.config.api_key}" }
63
+ end
64
+
65
+ def domain_header
66
+ return {} unless GetResponse.config.domain_header
67
+ { 'X-Domain' => GetResponse.config.domain_header }
68
+ end
69
+
70
+ def logging(msg)
71
+ puts "[GETRESPONSE-LOG] #{msg}" if GetResponse.config.verbose
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,17 @@
1
+ module GetResponse
2
+ class Response
3
+ def initialize(response)
4
+ @response = response
5
+ end
6
+
7
+ def body
8
+ JSON.parse(@response.body)
9
+ rescue JSON::ParserError => e
10
+ {}
11
+ end
12
+
13
+ def success?
14
+ [200, 201, 202].include? @response.status
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module GetResponse
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: get_response
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Faizal Zakaria
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-05-16 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.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
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.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
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.4
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.4
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: json
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.8.6
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.8.6
97
+ - !ruby/object:Gem::Dependency
98
+ name: faraday
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.9.2
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.9.2
111
+ description: Get Response Ruby Library ...
112
+ email:
113
+ - phaibusiness@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - bin/console
126
+ - bin/setup
127
+ - get_response.gemspec
128
+ - lib/get_response.rb
129
+ - lib/get_response/api.rb
130
+ - lib/get_response/request.rb
131
+ - lib/get_response/response.rb
132
+ - lib/get_response/version.rb
133
+ homepage: https://github.com/kfit-dev/getresponse_ruby
134
+ licenses:
135
+ - MIT
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 2.6.11
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: Get Response Ruby Library
157
+ test_files: []