bolzter 0.0.2

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,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MmJjZTk0MGI4MmUzNTNiNjMwMTgxY2EyODFiZjA0YzRiOGEyOTc1MA==
5
+ data.tar.gz: !binary |-
6
+ Y2EwNTAwZDA0YTk5MmFjMTVmYjhlOWU0YTVkYjE0YTI1ZDQ3NzM5MA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ Zjc1ZDA1NTRlODUyNmEzZGRiM2NlMmRiMGI4ZWQwNTE2ZDI2M2EwMDExYzEw
10
+ ZGRlZTMzMTc1YmY0YTUwMjY3ODVkY2VlMjhmM2U0MGU4ZWI2Y2M3YjZlZDhl
11
+ MjdlNTE1MGI5OTg4NmVhNjFlYjcxNzc2MzEyZWRiYTMwMDYyNzI=
12
+ data.tar.gz: !binary |-
13
+ OWYzNTQwYmJhZGMwNGZkYjZmNzRlMmQ2MzY0MjhlMmY4M2IwOWVkNmY5MDQx
14
+ MmEzNDNlYjQ5OGUxNGU5MTQzNTQ0MzhkNzUyMGM5Y2JlYzI0YTZkN2RjNzdj
15
+ NWIzNjQyMWFkOTFmZWY0OGUxZWY2NDdiNzY3OGVmZmZmZWM2NmE=
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bolzter.gemspec
4
+ gemspec
5
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 John
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,119 @@
1
+ # Bolzter
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'bolzter'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install bolzter
20
+
21
+ ## Usage
22
+
23
+ ###1. Setting API key
24
+
25
+ ```ruby
26
+ Bolzter::Bolzter.set_credentials("YOUR_USERNAME", "YOUR_API_KEY")
27
+ ```
28
+
29
+ Output
30
+
31
+ ```ruby
32
+ => {:username=>"YOUR_USERNAME", :api_key=>"YOUR_API_KEY"}
33
+ ```
34
+
35
+
36
+ ###2. Getting users
37
+
38
+ ```ruby
39
+ $ Bolzter::Bolzter.users
40
+ ```
41
+
42
+ Output
43
+
44
+ ```ruby
45
+ $ => {"meta"=>{"limit"=>20, "next"=>nil, "offset"=>0, "previous"=>nil, "total_count"=>1}, "objects"=>[{"email"=>"user@example.com", "first_name"=>"Test", "id"=>12, "last_login"=>"2014-07-14T12:15:22", "last_name"=>"User", "resource_uri"=>"/api/v2.1/user/12/"}]}
46
+ ```
47
+
48
+ ###3. Getting a user
49
+
50
+ ```ruby
51
+ Bolzter::Bolzter.user(id)
52
+ ```
53
+
54
+ ###4. Getting campaigns
55
+
56
+ ```ruby
57
+ Bolzter::Bolzter.campaigns
58
+ ```
59
+
60
+ ###5. Getting a campaign
61
+
62
+ ```ruby
63
+ Bolzter::Bolzter.campaign
64
+ ```
65
+
66
+ ###6. Getting persons
67
+
68
+ ```ruby
69
+ Bolzter::Bolzter.persons
70
+ ```
71
+
72
+ ###7. Getting a person
73
+
74
+ ```ruby
75
+ Bolzter::Bolzter.person(id)
76
+ ```
77
+
78
+ ###8. Updating a person
79
+
80
+ ```ruby
81
+ params = {
82
+ "first_name" => "NewFName",
83
+ "last_name" => "NewLName",
84
+ ...
85
+ }
86
+ Bolzter::Bolzter.update_person(id, params)
87
+ ```
88
+
89
+ ###9. Deleting a person
90
+
91
+ ```ruby
92
+ Bolzter::Bolzter.delete_person(id)
93
+ ```
94
+
95
+ ###10. Creating a lead
96
+
97
+ ```ruby
98
+ params = {
99
+ "first_name" => "fName",
100
+ "last_name" => "lName",
101
+ "email" => "fname.lname@example.com",
102
+ "campaign" => campaign_id, # Or campaign resource. For example /api/v2.1/campaign/42/
103
+ ...
104
+ }
105
+ Bolzter::Bolzter.create_lead(params)
106
+ ```
107
+
108
+ Output:
109
+
110
+ $=> #<Net::HTTPCreated 201 CREATED readbody=true>
111
+
112
+
113
+ ## Contributing
114
+
115
+ 1. Fork it ( https://github.com/rails-webmaster/bolzter/fork )
116
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
117
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
118
+ 4. Push to the branch (`git push origin my-new-feature`)
119
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bolzter.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bolzter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bolzter"
8
+ spec.version = Bolzter::VERSION
9
+ spec.authors = ["John"]
10
+ spec.email = ["rails.john.smith@gmail.com"]
11
+ spec.summary = "This gem supports an interface to Bolzter APIs"
12
+ spec.description = "This gem supports an interface to Bolzter APIs"
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = ["Gemfile", "LICENSE.txt", "README.md", "Rakefile", "bolzter.gemspec", "lib/bolzter.rb", "lib/bolzter/version.rb"]
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_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,3 @@
1
+ module Bolzter
2
+ VERSION = "0.0.2"
3
+ end
data/lib/bolzter.rb ADDED
@@ -0,0 +1,201 @@
1
+ require "bolzter/version"
2
+ require 'uri'
3
+ require 'net/http'
4
+ require 'json'
5
+ require 'yaml'
6
+
7
+ module Bolzter
8
+ class Bolzter
9
+ # Class level variables
10
+ @@api_root = "https://social.bolzter.com/api/v2.1/"
11
+ @@username = ""
12
+ @@api_key = ""
13
+ @@end_point = "user"
14
+
15
+ # => Set credential. It should be called before call APIs.
16
+ def self.set_credentials(username, api_key)
17
+ @@username = username
18
+ @@api_key = api_key
19
+ {:username => username, :api_key => api_key}
20
+ end
21
+
22
+ def self.set_credentials
23
+ conf_file = File.join(Rails.root, 'config', 'bolzter.yml').to_s
24
+ if File.exists?(conf_file)
25
+ config = YAML.load_file(conf_file)
26
+ self.set_credentials(config["username"], config["api_key"])
27
+ else
28
+ puts "conf/bolzter.yml file does not exist. Please copy bolzter.yml.example file."
29
+ end
30
+ end
31
+
32
+ # => Creating uri path
33
+ def self.make_uri(end_point)
34
+
35
+ @@api_root + end_point + "/?username=" + @@username + "&api_key=" + @@api_key
36
+ end
37
+
38
+ # => Getting api root uri
39
+ def self.api_root
40
+
41
+ @@api_root
42
+ end
43
+
44
+ # => Getting username. It will be email address.
45
+ def self.username
46
+
47
+ @@username
48
+ end
49
+
50
+ # => Getting api_key. It can be found in your Bolzter account page.
51
+ def self.api_key
52
+
53
+ @@api_key
54
+ end
55
+
56
+ # => Getting all users
57
+ # => A list of your users, actually there is 1 user in the list (id, first_name, last_name, email, last_login).
58
+ def self.users
59
+ uri = URI.parse(make_uri("user"))
60
+ Net::HTTP.start(uri.host, uri.port,
61
+ :use_ssl => uri.scheme == 'https',
62
+ :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
63
+
64
+ request = Net::HTTP::Get.new uri.request_uri
65
+
66
+ @response = http.request request # Net::HTTPResponse object
67
+ end
68
+
69
+ JSON.parse @response.body
70
+ end
71
+
72
+ # => Getting a user from user Identity
73
+ # => A list of your users, actually there is 1 user in the list (id, first_name, last_name, email, last_login).
74
+ def self.user id
75
+ uri = URI.parse(make_uri("user/" + id.to_s))
76
+ Net::HTTP.start(uri.host, uri.port,
77
+ :use_ssl => uri.scheme == 'https',
78
+ :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
79
+
80
+ request = Net::HTTP::Get.new uri.request_uri
81
+
82
+ @response = http.request request # Net::HTTPResponse object
83
+ end
84
+
85
+ JSON.parse @response.body
86
+ end
87
+
88
+ # => Campaign resources of a user.
89
+ # => Response: List of campaigns of a user (id, name, description, start_date, end_date, status).
90
+ def self.campaigns
91
+ uri = URI.parse(make_uri("campaign"))
92
+ Net::HTTP.start(uri.host, uri.port,
93
+ :use_ssl => uri.scheme == 'https',
94
+ :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
95
+
96
+ request = Net::HTTP::Get.new uri.request_uri
97
+
98
+ @response = http.request request # Net::HTTPResponse object
99
+ end
100
+
101
+ JSON.parse @response.body
102
+ end
103
+
104
+ # => Response: Properties of a campaign object identified by {id} (id, name, description, start_date, end_date, status).
105
+ def self.campaign id
106
+ uri = URI.parse(make_uri("campaign/" + id.to_s))
107
+ Net::HTTP.start(uri.host, uri.port,
108
+ :use_ssl => uri.scheme == 'https',
109
+ :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
110
+
111
+ request = Net::HTTP::Get.new uri.request_uri
112
+
113
+ @response = http.request request # Net::HTTPResponse object
114
+ end
115
+
116
+ JSON.parse @response.body
117
+ end
118
+
119
+ # => Person resources of a user.
120
+ # => Response: List of person belongs to the user's campaigns (id, first_name, last_name, email, birthday, gender, phone, converted).
121
+ def self.persons
122
+ uri = URI.parse(make_uri("person"))
123
+ Net::HTTP.start(uri.host, uri.port,
124
+ :use_ssl => uri.scheme == 'https',
125
+ :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
126
+
127
+ request = Net::HTTP::Get.new uri.request_uri
128
+
129
+ @response = http.request request # Net::HTTPResponse object
130
+ end
131
+
132
+ JSON.parse @response.body
133
+ end
134
+
135
+ # => Response: Properties of a person object identified by {id} (id, first_name, last_name, email, birthday, gender, phone, converted).
136
+ def self.person id
137
+ uri = URI.parse(make_uri("person/" + id.to_s))
138
+ Net::HTTP.start(uri.host, uri.port,
139
+ :use_ssl => uri.scheme == 'https',
140
+ :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
141
+
142
+ request = Net::HTTP::Get.new uri.request_uri
143
+
144
+ @response = http.request request # Net::HTTPResponse object
145
+ end
146
+
147
+ JSON.parse @response.body
148
+ end
149
+
150
+ # => Response: Properties of a person object identified by {id} (id, first_name, last_name, email, birthday, gender, phone, converted).
151
+ # => Request: The required changes must be in JSON encoded format and don't forget to set the content type to 'application/json' (eg. {“converted”: true}).
152
+ # => Response: The proper HTTP code according to the success of the request.
153
+ def self.update_person(id, params)
154
+ uri = URI.parse(make_uri("person/" + id.to_s))
155
+ Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https', :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
156
+
157
+ request = Net::HTTP::Patch.new(uri.request_uri)
158
+ request.add_field('Content-Type', 'application/json')
159
+ request.body = JSON.dump(params)
160
+
161
+ @response = http.request request
162
+ end
163
+ end
164
+
165
+ # => Response: The proper HTTP status code.
166
+ def self.delete_person(id)
167
+ uri = URI.parse(make_uri("person/" + id.to_s))
168
+ Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https', :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
169
+
170
+ request = Net::HTTP::Delete.new(uri.request_uri)
171
+
172
+ @response = http.request request
173
+ end
174
+ end
175
+
176
+ # => Creating Person object and register it for the appropriate Campaign in one step.
177
+ # => Field name Required Description
178
+ # => first_name yes First name in max. 75 length
179
+ # => last_name yes Last name in max. 75 length
180
+ # => email yes Valid email address in max. 100 length
181
+ # => campaign yes Campaign resource identifier which can be a numeric ID or a resource URI (eg. /api/v2.1/campaign/42/)
182
+ # => phone no Phone number in max. 100 length
183
+ # => birthday no Birthday in form YYYY-MM-DD
184
+ # => country no Country name according to ISO-3166 in max. 50 length
185
+ # => state no State of the country in max. 50 length
186
+ # => city no City name in max. 100 length
187
+ # => facebook_access_token no Valid Facebook User Access Token which is given by the user. Pay attention that the FB App which requested the permission must be the same as set for the campaign in Bolzter.
188
+ # => tracking_cookie no For such cases when the user's activities are tracked in browsers and the registration process is not going through a web page but the API. In order to be able to associate this tracked history to the lead we need the tracking cookie (bolzter_premarker).
189
+ def self.create_lead(params)
190
+ uri = URI.parse(make_uri("lead"))
191
+ Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https', :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
192
+
193
+ request = Net::HTTP::Post.new(uri.request_uri)
194
+ request.add_field('Content-Type', 'application/json')
195
+ request.body = JSON.dump(params)
196
+
197
+ @response = http.request request
198
+ end
199
+ end
200
+ end
201
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bolzter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - John
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-11 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
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
+ description: This gem supports an interface to Bolzter APIs
42
+ email:
43
+ - rails.john.smith@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - Gemfile
49
+ - LICENSE.txt
50
+ - README.md
51
+ - Rakefile
52
+ - bolzter.gemspec
53
+ - lib/bolzter.rb
54
+ - lib/bolzter/version.rb
55
+ homepage: ''
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 2.4.4
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: This gem supports an interface to Bolzter APIs
79
+ test_files: []