beeleads 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/beeleads.gemspec +29 -0
- data/lib/beeleads/version.rb +3 -0
- data/lib/beeleads.rb +38 -0
- data/spec/beeleads_spec.rb +60 -0
- data/spec/spec_helper.rb +22 -0
- metadata +161 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 TODO: Write your name
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Beeleads
|
2
|
+
|
3
|
+
A Ruby interface to the Beeleads API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'beeleads'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install beeleads
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
In order to use Beeleads' Lead Integration API (version 1.0) make sure you have the following information:
|
22
|
+
|
23
|
+
* Affiliate ID
|
24
|
+
* API Secret
|
25
|
+
* Offer ID
|
26
|
+
|
27
|
+
If you are missing any of this info, please contact suporte@beeleads.com.br.
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'beeleads'
|
31
|
+
client = Beeleads::Client.new({:api_affiliate_id => ENV['API_AFFILIATE_ID'], :api_secret => ENV['API_SECRET'], :api_offer_id => ENV['API_OFFER_ID']})
|
32
|
+
client.lead({'email' => 'sample@example.net', 'firstname' => 'Tiago'})
|
33
|
+
```
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
1. Fork it
|
38
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
39
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
40
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
41
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/beeleads.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'beeleads/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "beeleads"
|
8
|
+
spec.version = Beeleads::VERSION
|
9
|
+
spec.authors = ["Décio Ferreira"]
|
10
|
+
spec.email = ["decio.ferreira@decioferreira.com"]
|
11
|
+
spec.description = %q{A Ruby interface to the Beeleads API.}
|
12
|
+
spec.summary = %q{A Ruby interface to the Beeleads API.}
|
13
|
+
spec.homepage = "https://github.com/decioferreira/beeleads"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'faraday'
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
|
26
|
+
spec.add_development_dependency 'rspec', '~> 2.13.0'
|
27
|
+
spec.add_development_dependency 'simplecov'
|
28
|
+
spec.add_development_dependency 'webmock'
|
29
|
+
end
|
data/lib/beeleads.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Beeleads
|
5
|
+
class Client
|
6
|
+
def initialize(options={})
|
7
|
+
instance_variable_set(:@api_url, 'https://hive.bldstools.com/api.php/v1/lead/')
|
8
|
+
self.class.keys.each do |key|
|
9
|
+
instance_variable_set(:"@#{key}", options[key]) if options[key]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def lead(data)
|
14
|
+
uri = URI(@api_url)
|
15
|
+
conn = Faraday.new(:url => "#{uri.scheme}://#{uri.host}", :ssl => {:verify => false})
|
16
|
+
response = conn.get uri.path, {'token' => self.class.token(@api_secret, data), 'affiliate_id' => @api_affiliate_id, 'offer_id' => @api_offer_id, 'field' => data}
|
17
|
+
JSON.parse(response.body)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def self.keys
|
22
|
+
@keys ||= [
|
23
|
+
:api_url,
|
24
|
+
:api_affiliate_id,
|
25
|
+
:api_secret,
|
26
|
+
:api_offer_id
|
27
|
+
]
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.token(secret, data)
|
31
|
+
Digest::SHA1.hexdigest "#{secret}#{self.token_query(data)}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.token_query(data)
|
35
|
+
encoded_form_data = URI.encode_www_form(data)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'beeleads'
|
3
|
+
|
4
|
+
describe Beeleads::Client do
|
5
|
+
describe 'api_url' do
|
6
|
+
it 'has a default value' do
|
7
|
+
client = Beeleads::Client.new()
|
8
|
+
client.instance_variable_get(:@api_url).should eq('https://hive.bldstools.com/api.php/v1/lead/')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '.new' do
|
13
|
+
%w(api_url api_affiliate_id api_secret api_offer_id).each do |k|
|
14
|
+
it 'should set the #{k} option' do
|
15
|
+
client = Beeleads::Client.new({k.to_sym => k})
|
16
|
+
client.instance_variable_get(:"@#{k}").should eq(k)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should not set the any_other option' do
|
21
|
+
client = Beeleads::Client.new({:any_other => 'something'})
|
22
|
+
client.instance_variable_get(:@any_other).should be_nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#lead' do
|
27
|
+
subject { Beeleads::Client.new({:api_affiliate_id => 123, :api_secret => 'secret', :api_offer_id => 7}) }
|
28
|
+
let(:lead) { { :email => 'sample@example.net', :firstname => 'Tiago' } }
|
29
|
+
|
30
|
+
before :each do
|
31
|
+
Beeleads::Client.stub(:token).with('secret', lead) { 'token' }
|
32
|
+
stub_request(:get, 'https://hive.bldstools.com/api.php/v1/lead/').with(:query => {'token' => 'token', 'affiliate_id' => 123, 'offer_id' => 7, :field => lead}).to_return(:body => {'result' => 'test'}.to_json)
|
33
|
+
@response = subject.lead(lead)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should make a get request' do
|
37
|
+
a_request(:get, 'https://hive.bldstools.com/api.php/v1/lead/').with(:query => {'token' => 'token', 'affiliate_id' => 123, 'offer_id' => 7, 'field' => lead}).should have_been_made.once
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should make the request without peer verification' do
|
41
|
+
pending
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should return JSON parsed body' do
|
45
|
+
@response.should eq({'result' => 'test'})
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '.token' do
|
50
|
+
it 'should return the correct token' do
|
51
|
+
Beeleads::Client.class_eval { token('yoursecret', { :email => 'sample@example.net', :firstname => 'Tiago' }) }.should eq('534da26a597e62b65b25711eb200197fc59ceb14')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '.token_query' do
|
56
|
+
it 'should return the correct encoded form data' do
|
57
|
+
Beeleads::Client.class_eval { token_query({ :email => 'sample@example.net', :firstname => 'Tiago' }) }.should eq('email=sample%40example.net&firstname=Tiago')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
3
|
+
|
4
|
+
require 'webmock/rspec'
|
5
|
+
|
6
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
7
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
8
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
9
|
+
# loaded once.
|
10
|
+
#
|
11
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
14
|
+
config.run_all_when_everything_filtered = true
|
15
|
+
config.filter_run :focus
|
16
|
+
|
17
|
+
# Run specs in random order to surface order dependencies. If you find an
|
18
|
+
# order dependency and want to debug it, you can fix the order by providing
|
19
|
+
# the seed, which is printed after each run.
|
20
|
+
# --seed 1234
|
21
|
+
config.order = 'random'
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: beeleads
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Décio Ferreira
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bundler
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.3'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1.3'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 2.13.0
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 2.13.0
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: simplecov
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: webmock
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
description: A Ruby interface to the Beeleads API.
|
111
|
+
email:
|
112
|
+
- decio.ferreira@decioferreira.com
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files: []
|
116
|
+
files:
|
117
|
+
- .gitignore
|
118
|
+
- .rspec
|
119
|
+
- Gemfile
|
120
|
+
- LICENSE.txt
|
121
|
+
- README.md
|
122
|
+
- Rakefile
|
123
|
+
- beeleads.gemspec
|
124
|
+
- lib/beeleads.rb
|
125
|
+
- lib/beeleads/version.rb
|
126
|
+
- spec/beeleads_spec.rb
|
127
|
+
- spec/spec_helper.rb
|
128
|
+
homepage: https://github.com/decioferreira/beeleads
|
129
|
+
licenses:
|
130
|
+
- MIT
|
131
|
+
post_install_message:
|
132
|
+
rdoc_options: []
|
133
|
+
require_paths:
|
134
|
+
- lib
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
none: false
|
137
|
+
requirements:
|
138
|
+
- - ! '>='
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
segments:
|
142
|
+
- 0
|
143
|
+
hash: 218675633
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
segments:
|
151
|
+
- 0
|
152
|
+
hash: 218675633
|
153
|
+
requirements: []
|
154
|
+
rubyforge_project:
|
155
|
+
rubygems_version: 1.8.25
|
156
|
+
signing_key:
|
157
|
+
specification_version: 3
|
158
|
+
summary: A Ruby interface to the Beeleads API.
|
159
|
+
test_files:
|
160
|
+
- spec/beeleads_spec.rb
|
161
|
+
- spec/spec_helper.rb
|