libring 0.0.1 → 1.0.0
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 +4 -4
- data/lib/libring.rb +9 -3
- data/lib/libring/api.rb +118 -0
- data/lib/libring/contact.rb +100 -0
- data/lib/libring/event.rb +122 -0
- data/lib/libring/product.rb +40 -0
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a666fd8e05bc7e4911790eb9264e703103ac7c0
|
4
|
+
data.tar.gz: 7e7849d7d7cabc1fe3b588df0210210cb164fdc1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5dcfb1dc2593c24c12ebccedb4d4a336bd1b0097a5013f5d93d3588c55d657647f29ab7c68ff34cc389c74810b583b60f3ad3e8bbeae3b4ccfac49a9c748d92
|
7
|
+
data.tar.gz: 252d491be33afa94e544848ddd0404d7289be23142cf63ea8ed83adc336d5e82deaf1bc841e5f8bdba65b2a8c8a9b88ba976e866c75d3b5505249dd29b49e316
|
data/lib/libring.rb
CHANGED
data/lib/libring/api.rb
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
class Libring::API
|
2
|
+
|
3
|
+
attr_reader :token
|
4
|
+
|
5
|
+
def initialize(token)
|
6
|
+
@token = token
|
7
|
+
|
8
|
+
true
|
9
|
+
end
|
10
|
+
|
11
|
+
def event_track(contact)
|
12
|
+
|
13
|
+
require "net/https"
|
14
|
+
require "uri"
|
15
|
+
require "json"
|
16
|
+
|
17
|
+
uri = URI.parse("https://api.libring.com/v2/event_tracker")
|
18
|
+
|
19
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
20
|
+
https.use_ssl = true
|
21
|
+
|
22
|
+
req = Net::HTTP::Post.new(uri.request_uri, initheader = {'Content-Type' =>'application/json', 'Authorization' => "Token #{@token}"})
|
23
|
+
|
24
|
+
req.set_form_data({ libring: { "#{contact.contact_code}" => { attributes: contact.attributes, location: contact.location, events: contact.events } }.to_json })
|
25
|
+
|
26
|
+
response = https.request(req)
|
27
|
+
|
28
|
+
if response.body == ""
|
29
|
+
{ success: true }
|
30
|
+
else
|
31
|
+
{ error: response.body, success: false }
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_contact(contact_code)
|
37
|
+
|
38
|
+
require "net/https"
|
39
|
+
require "uri"
|
40
|
+
require "json"
|
41
|
+
|
42
|
+
uri = URI.parse("https://api.libring.com/v2/contact/get/" + contact_code.to_s)
|
43
|
+
|
44
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
45
|
+
https.use_ssl = true
|
46
|
+
|
47
|
+
req = Net::HTTP::Get.new(uri.request_uri, initheader = {'Content-Type' =>'application/json', 'Authorization' => "Token #{@token}"})
|
48
|
+
|
49
|
+
resp = https.request(req)
|
50
|
+
|
51
|
+
resp.body
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
def update_attribute(contact_code, name, value, type)
|
56
|
+
|
57
|
+
require "net/https"
|
58
|
+
require "uri"
|
59
|
+
require "json"
|
60
|
+
|
61
|
+
uri = URI.parse("https://api.libring.com/v2/contact/put")
|
62
|
+
|
63
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
64
|
+
https.use_ssl = true
|
65
|
+
|
66
|
+
req = Net::HTTP::Post.new(uri.request_uri, initheader = {'Content-Type' =>'application/json', 'Authorization' => "Token #{@token}"})
|
67
|
+
|
68
|
+
req.set_form_data({libring: { "#{contact_code}"=> { "#{name}" => { value: "#{value}", type: "#{type}" } }}.to_json })
|
69
|
+
|
70
|
+
resp = https.request(req)
|
71
|
+
|
72
|
+
if resp.body == "OK"
|
73
|
+
{ success: true }
|
74
|
+
else
|
75
|
+
{ error: response.body, success: false }
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
def get_message(contact_code)
|
81
|
+
|
82
|
+
require "net/https"
|
83
|
+
require "uri"
|
84
|
+
require "json"
|
85
|
+
|
86
|
+
uri = URI.parse("https://api.libring.com/v2/messages/get/" + contact_code.to_s)
|
87
|
+
|
88
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
89
|
+
https.use_ssl = true
|
90
|
+
|
91
|
+
req = Net::HTTP::Get.new(uri.request_uri, initheader = {'Content-Type' =>'application/json', 'Authorization' => "Token #{@token}"})
|
92
|
+
|
93
|
+
resp = https.request(req)
|
94
|
+
|
95
|
+
resp.body
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
def get_all_messages
|
100
|
+
|
101
|
+
require "net/https"
|
102
|
+
require "uri"
|
103
|
+
require "json"
|
104
|
+
|
105
|
+
uri = URI.parse("https://api.libring.com/v2/messages/get_all")
|
106
|
+
|
107
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
108
|
+
https.use_ssl = true
|
109
|
+
|
110
|
+
req = Net::HTTP::Get.new(uri.request_uri, initheader = {'Content-Type' =>'application/json', 'Authorization' => "Token #{@token}"})
|
111
|
+
|
112
|
+
resp = https.request(req)
|
113
|
+
|
114
|
+
resp.body
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
class Libring::Contact
|
2
|
+
|
3
|
+
attr_reader :contact_code, :attributes, :location, :events
|
4
|
+
|
5
|
+
def initialize(contact_code)
|
6
|
+
|
7
|
+
@contact_code = contact_code
|
8
|
+
@attributes = {}
|
9
|
+
@location = {}
|
10
|
+
@events = {}
|
11
|
+
|
12
|
+
true
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_attribute(name, value, type)
|
17
|
+
|
18
|
+
if name == "" || value == "" || type == "" || (type != "string" && type != "decimal" && type != "integer" && type != "datetime")
|
19
|
+
|
20
|
+
"You must inform valid params for name, value and type"
|
21
|
+
|
22
|
+
else
|
23
|
+
|
24
|
+
@attributes[name] = {}
|
25
|
+
@attributes[name]["value"] = value
|
26
|
+
@attributes[name]["type"] = type
|
27
|
+
|
28
|
+
true
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_attributes
|
35
|
+
|
36
|
+
@attributes
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
def clean_attributes
|
41
|
+
|
42
|
+
@attributes = {}
|
43
|
+
|
44
|
+
true
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
def update_location(country, state = nil, city = nil)
|
49
|
+
|
50
|
+
@location["country"] = country
|
51
|
+
@location["state"] = state if !state.nil?
|
52
|
+
@location["city"] = city if !city.nil?
|
53
|
+
|
54
|
+
true
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
def get_location
|
59
|
+
|
60
|
+
@location
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
def clean_location
|
65
|
+
|
66
|
+
@location = {}
|
67
|
+
|
68
|
+
true
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
def add_event(event)
|
73
|
+
|
74
|
+
require 'json'
|
75
|
+
|
76
|
+
if event.source != ""
|
77
|
+
|
78
|
+
@events["#{event.date}"] = [] if !@events["#{event.date}"]
|
79
|
+
|
80
|
+
@events["#{event.date}"].push( { :source => event.source, :source_referral => event.source_referral, :page_title => event.page_title, :ip => event.ip, :invitees => event.invitees, :metadata => event.metadata, :products => event.products } )
|
81
|
+
|
82
|
+
true
|
83
|
+
|
84
|
+
else
|
85
|
+
|
86
|
+
"Event source required"
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
def clean_events
|
93
|
+
|
94
|
+
@events = {}
|
95
|
+
|
96
|
+
true
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
class Libring::Event
|
2
|
+
|
3
|
+
attr_reader :date, :source, :source_referral, :page_title, :ip, :invitees, :metadata, :products
|
4
|
+
|
5
|
+
require 'date'
|
6
|
+
|
7
|
+
def initialize(date)
|
8
|
+
|
9
|
+
@date = DateTime.parse(date)
|
10
|
+
|
11
|
+
@invitees = []
|
12
|
+
@metadata = {}
|
13
|
+
@products = {}
|
14
|
+
@source = ""
|
15
|
+
@source_referral = ""
|
16
|
+
@page_title = ""
|
17
|
+
@ip = ""
|
18
|
+
|
19
|
+
true
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
def set_source(data)
|
24
|
+
|
25
|
+
@source = data
|
26
|
+
|
27
|
+
true
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
def set_source_referral(data)
|
32
|
+
|
33
|
+
@source_referral = data
|
34
|
+
|
35
|
+
true
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
def set_page_title(data)
|
40
|
+
|
41
|
+
@page_title = data
|
42
|
+
|
43
|
+
true
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
def set_ip(data)
|
48
|
+
|
49
|
+
if /^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$/.match(data)
|
50
|
+
|
51
|
+
@ip = data
|
52
|
+
|
53
|
+
true
|
54
|
+
|
55
|
+
else
|
56
|
+
|
57
|
+
"Invalid IP"
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
def add_invitee(name)
|
64
|
+
|
65
|
+
@invitees.push(name)
|
66
|
+
|
67
|
+
true
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
def clean_invitees
|
72
|
+
|
73
|
+
@invitees = []
|
74
|
+
|
75
|
+
true
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
def add_metadata(name, value)
|
80
|
+
|
81
|
+
@metadata[name] = value
|
82
|
+
|
83
|
+
true
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
def clean_metadata
|
88
|
+
|
89
|
+
@metadata = {}
|
90
|
+
|
91
|
+
true
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
def add_product(product)
|
96
|
+
|
97
|
+
if product.unit_amount != -1
|
98
|
+
|
99
|
+
@products["#{product.sku}"] = {}
|
100
|
+
@products["#{product.sku}"][:name] = product.name
|
101
|
+
@products["#{product.sku}"][:unit_amount] = product.unit_amount
|
102
|
+
@products["#{product.sku}"][:quantity] = product.quantity
|
103
|
+
|
104
|
+
true
|
105
|
+
|
106
|
+
else
|
107
|
+
|
108
|
+
"Product unit amount required"
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
def clean_products
|
115
|
+
|
116
|
+
@products = {}
|
117
|
+
|
118
|
+
true
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class Libring::Product
|
2
|
+
|
3
|
+
attr_reader :sku, :name, :unit_amount, :quantity
|
4
|
+
|
5
|
+
def initialize(sku)
|
6
|
+
|
7
|
+
@sku = sku
|
8
|
+
@name = sku
|
9
|
+
@quantity = 1
|
10
|
+
@unit_amount = -1
|
11
|
+
|
12
|
+
true
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
def set_name(data)
|
17
|
+
|
18
|
+
@name = data
|
19
|
+
|
20
|
+
true
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
def set_unit_amount(data)
|
25
|
+
|
26
|
+
@unit_amount = data
|
27
|
+
|
28
|
+
true
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
def set_quantity(data)
|
33
|
+
|
34
|
+
@quantity = data
|
35
|
+
|
36
|
+
true
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libring
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vitor Pereira
|
@@ -17,6 +17,10 @@ extensions: []
|
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
19
|
- lib/libring.rb
|
20
|
+
- lib/libring/api.rb
|
21
|
+
- lib/libring/contact.rb
|
22
|
+
- lib/libring/event.rb
|
23
|
+
- lib/libring/product.rb
|
20
24
|
homepage: http://rubygems.org/gems/libring
|
21
25
|
licenses:
|
22
26
|
- MIT
|