beeleads 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +3 -0
- data/README.md +40 -4
- data/beeleads.gemspec +2 -2
- data/lib/beeleads.rb +6 -1
- data/lib/beeleads/version.rb +1 -1
- data/spec/beeleads_spec.rb +33 -11
- data/spec/spec_helper.rb +0 -1
- metadata +26 -45
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 70d75aa6337b2acdd3b033376719c0d0a26ba945
|
4
|
+
data.tar.gz: 04c73f75dae7a50ee9392a9e88c541c68f402231
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e0f6aeefcc5bc627b80df3efd4198d1667138beef8d7249905df16a8590487b00d26c0b9c65a1e59af876efc32ec27b968e38728127d3dd7e4c0369d6a24443f
|
7
|
+
data.tar.gz: d3b49639412f29d7ba2217ca355df3cb38eb1dd0c13184873a1d45401bb685d1f7cefa31525a047d858d0625abef5fa44f2fb1914768939a212e67c5a49c4312
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Beeleads
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/decioferreira/beeleads.png?branch=master)](https://travis-ci.org/decioferreira/beeleads)
|
4
|
+
|
3
5
|
A Ruby interface to the Beeleads API.
|
4
6
|
|
5
7
|
## Installation
|
@@ -20,18 +22,52 @@ Or install it yourself as:
|
|
20
22
|
|
21
23
|
In order to use Beeleads' Lead Integration API (version 1.0) make sure you have the following information:
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
25
|
+
* Affiliate ID
|
26
|
+
* API Secret
|
27
|
+
* Offer ID
|
26
28
|
|
27
29
|
If you are missing any of this info, please contact suporte@beeleads.com.br.
|
28
30
|
|
29
31
|
```ruby
|
30
32
|
require 'beeleads'
|
31
33
|
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'})
|
34
|
+
response = client.lead({'email' => 'sample@example.net', 'firstname' => 'Tiago'})
|
33
35
|
```
|
34
36
|
|
37
|
+
The result has the following structure:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
{
|
41
|
+
"request" => {
|
42
|
+
"time" => "2013-03-29 10:10:00",
|
43
|
+
"data" => {
|
44
|
+
"token" => "0d91dc50fc537bf975d91468efd381a1d8c250e1",
|
45
|
+
"affiliate_id" => "1234",
|
46
|
+
"offer_id" => "0",
|
47
|
+
"field" => {
|
48
|
+
"email" => "sample@example.net",
|
49
|
+
"firstname" => "Tiago"
|
50
|
+
}
|
51
|
+
}
|
52
|
+
},
|
53
|
+
"response" => {
|
54
|
+
"status" => 200,
|
55
|
+
"message" => "OK"
|
56
|
+
"data" => {
|
57
|
+
"lead_id" => "573a872f9f68149b867dde997f5160f00f79cff3",
|
58
|
+
"status"=>"PENDING_APPROVAL"
|
59
|
+
}
|
60
|
+
}
|
61
|
+
}
|
62
|
+
```
|
63
|
+
|
64
|
+
The response status codes can be:
|
65
|
+
|
66
|
+
* 200 - OK
|
67
|
+
* 400 - Invalid Request Data
|
68
|
+
* 401 - Invalid Token
|
69
|
+
* 500 - Internal Error
|
70
|
+
|
35
71
|
## Contributing
|
36
72
|
|
37
73
|
1. Fork it
|
data/beeleads.gemspec
CHANGED
@@ -20,10 +20,10 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_dependency 'faraday'
|
22
22
|
|
23
|
-
spec.add_development_dependency "bundler", "~> 1.
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
24
24
|
spec.add_development_dependency "rake"
|
25
25
|
|
26
|
-
spec.add_development_dependency 'rspec', '~>
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.1.0'
|
27
27
|
spec.add_development_dependency 'simplecov'
|
28
28
|
spec.add_development_dependency 'webmock'
|
29
29
|
end
|
data/lib/beeleads.rb
CHANGED
@@ -32,7 +32,12 @@ module Beeleads
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def self.token_query(data)
|
35
|
-
|
35
|
+
URI.encode_www_form(sanitized_data(data))
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.sanitized_data(data)
|
39
|
+
data_without_nil = Hash[data.map{ |k, v| [k, v || ''] }]
|
40
|
+
Hash[data_without_nil.sort_by(&:first)]
|
36
41
|
end
|
37
42
|
end
|
38
43
|
end
|
data/lib/beeleads/version.rb
CHANGED
data/spec/beeleads_spec.rb
CHANGED
@@ -5,7 +5,7 @@ describe Beeleads::Client do
|
|
5
5
|
describe 'api_url' do
|
6
6
|
it 'has a default value' do
|
7
7
|
client = Beeleads::Client.new()
|
8
|
-
client.instance_variable_get(:@api_url).
|
8
|
+
expect(client.instance_variable_get(:@api_url)).to eq('https://hive.bldstools.com/api.php/v1/lead/')
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
@@ -13,13 +13,13 @@ describe Beeleads::Client do
|
|
13
13
|
%w(api_url api_affiliate_id api_secret api_offer_id).each do |k|
|
14
14
|
it 'should set the #{k} option' do
|
15
15
|
client = Beeleads::Client.new({k.to_sym => k})
|
16
|
-
client.instance_variable_get(:"@#{k}").
|
16
|
+
expect(client.instance_variable_get(:"@#{k}")).to eq(k)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'should not set the any_other option' do
|
21
21
|
client = Beeleads::Client.new({:any_other => 'something'})
|
22
|
-
client.instance_variable_get(:@any_other).
|
22
|
+
expect(client.instance_variable_get(:@any_other)).to be_nil
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -28,33 +28,55 @@ describe Beeleads::Client do
|
|
28
28
|
let(:lead) { { :email => 'sample@example.net', :firstname => 'Tiago' } }
|
29
29
|
|
30
30
|
before :each do
|
31
|
-
Beeleads::Client.
|
31
|
+
allow(Beeleads::Client).to receive(:token).with('secret', lead) { 'token' }
|
32
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
33
|
@response = subject.lead(lead)
|
34
34
|
end
|
35
35
|
|
36
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}).
|
37
|
+
expect(a_request(:get, 'https://hive.bldstools.com/api.php/v1/lead/').with(:query => {'token' => 'token', 'affiliate_id' => 123, 'offer_id' => 7, 'field' => lead})).to have_been_made.once
|
38
38
|
end
|
39
39
|
|
40
|
-
|
41
|
-
pending
|
42
|
-
end
|
40
|
+
xit 'should make the request without peer verification'
|
43
41
|
|
44
42
|
it 'should return JSON parsed body' do
|
45
|
-
@response.
|
43
|
+
expect(@response).to eq({'result' => 'test'})
|
46
44
|
end
|
47
45
|
end
|
48
46
|
|
49
47
|
describe '.token' do
|
48
|
+
def beeleads_token(params)
|
49
|
+
Beeleads::Client.class_eval { token('yoursecret', params) }
|
50
|
+
end
|
51
|
+
|
50
52
|
it 'should return the correct token' do
|
51
|
-
|
53
|
+
expect(beeleads_token({ :email => 'sample@example.net', :firstname => 'Tiago' })).to eq('534da26a597e62b65b25711eb200197fc59ceb14')
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should return the same token when the params order are different' do
|
57
|
+
expect(beeleads_token({ :email => 'sample@example.net', :firstname => 'Tiago' })).
|
58
|
+
to eq(beeleads_token({ :firstname => 'Tiago', :email => 'sample@example.net' }))
|
52
59
|
end
|
53
60
|
end
|
54
61
|
|
55
62
|
describe '.token_query' do
|
63
|
+
def token_query(params)
|
64
|
+
Beeleads::Client.class_eval { token_query(params) }
|
65
|
+
end
|
66
|
+
|
56
67
|
it 'should return the correct encoded form data' do
|
57
|
-
|
68
|
+
expect(token_query({ :email => 'sample@example.net', :firstname => 'Tiago' })).
|
69
|
+
to eq('email=sample%40example.net&firstname=Tiago')
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should convert nil to "" (empty string)' do
|
73
|
+
expect(token_query({ :email => 'sample@example.net', :firstname => nil})).
|
74
|
+
to eq('email=sample%40example.net&firstname=')
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'has keys in alphabetical order' do
|
78
|
+
expect(token_query({ :firstname => 'Tiago', :email => 'sample@example.net' })).
|
79
|
+
to eq('email=sample%40example.net&firstname=Tiago')
|
58
80
|
end
|
59
81
|
end
|
60
82
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -10,7 +10,6 @@ require 'webmock/rspec'
|
|
10
10
|
#
|
11
11
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
12
12
|
RSpec.configure do |config|
|
13
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
14
13
|
config.run_all_when_everything_filtered = true
|
15
14
|
config.filter_run :focus
|
16
15
|
|
metadata
CHANGED
@@ -1,110 +1,97 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: beeleads
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Décio Ferreira
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-12-15 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: faraday
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: bundler
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- - ~>
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
|
-
version: '1.
|
33
|
+
version: '1.7'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- - ~>
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
|
-
version: '1.
|
40
|
+
version: '1.7'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rake
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: rspec
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- - ~>
|
59
|
+
- - "~>"
|
68
60
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
61
|
+
version: 3.1.0
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- - ~>
|
66
|
+
- - "~>"
|
76
67
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
68
|
+
version: 3.1.0
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: simplecov
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - ">="
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: '0'
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - ">="
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: '0'
|
94
83
|
- !ruby/object:Gem::Dependency
|
95
84
|
name: webmock
|
96
85
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
86
|
requirements:
|
99
|
-
- -
|
87
|
+
- - ">="
|
100
88
|
- !ruby/object:Gem::Version
|
101
89
|
version: '0'
|
102
90
|
type: :development
|
103
91
|
prerelease: false
|
104
92
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
93
|
requirements:
|
107
|
-
- -
|
94
|
+
- - ">="
|
108
95
|
- !ruby/object:Gem::Version
|
109
96
|
version: '0'
|
110
97
|
description: A Ruby interface to the Beeleads API.
|
@@ -114,8 +101,9 @@ executables: []
|
|
114
101
|
extensions: []
|
115
102
|
extra_rdoc_files: []
|
116
103
|
files:
|
117
|
-
- .gitignore
|
118
|
-
- .rspec
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".travis.yml"
|
119
107
|
- Gemfile
|
120
108
|
- LICENSE.txt
|
121
109
|
- README.md
|
@@ -128,33 +116,26 @@ files:
|
|
128
116
|
homepage: https://github.com/decioferreira/beeleads
|
129
117
|
licenses:
|
130
118
|
- MIT
|
119
|
+
metadata: {}
|
131
120
|
post_install_message:
|
132
121
|
rdoc_options: []
|
133
122
|
require_paths:
|
134
123
|
- lib
|
135
124
|
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
-
none: false
|
137
125
|
requirements:
|
138
|
-
- -
|
126
|
+
- - ">="
|
139
127
|
- !ruby/object:Gem::Version
|
140
128
|
version: '0'
|
141
|
-
segments:
|
142
|
-
- 0
|
143
|
-
hash: 218675633
|
144
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
-
none: false
|
146
130
|
requirements:
|
147
|
-
- -
|
131
|
+
- - ">="
|
148
132
|
- !ruby/object:Gem::Version
|
149
133
|
version: '0'
|
150
|
-
segments:
|
151
|
-
- 0
|
152
|
-
hash: 218675633
|
153
134
|
requirements: []
|
154
135
|
rubyforge_project:
|
155
|
-
rubygems_version:
|
136
|
+
rubygems_version: 2.2.2
|
156
137
|
signing_key:
|
157
|
-
specification_version:
|
138
|
+
specification_version: 4
|
158
139
|
summary: A Ruby interface to the Beeleads API.
|
159
140
|
test_files:
|
160
141
|
- spec/beeleads_spec.rb
|