libring 0.0.1 → 1.0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b8f1f8d2c11c69a35a62e2971f9eacc7b4b11320
4
- data.tar.gz: b6faec899aaf90c0b6bc5c34abc51aca707b778c
3
+ metadata.gz: 6dd75a8f4caaa467f5b1deda8be625486fcd739a
4
+ data.tar.gz: 555b7dafd35e61ecaa537e55e50aef9a73608f03
5
5
  SHA512:
6
- metadata.gz: e1c12fa73ccaae19bc49081c71bbd9899f9c2b2d415a6718927770f55936278b121699441e83b3cca1a57713c9bbdc2fa6efd9caf0d90d431675c1260f2b9cca
7
- data.tar.gz: 381de41f68f7b19fd56890acacfbe6ac87f3a7af7bda712048d5591ee4bc06ae37a961baa226e057b4bd444f579e69ed61d21ab9fa532d258e02b613dd62851e
6
+ metadata.gz: 6093f6c4411cf1b2d0e1032534e86692d4f21b73dd5433dc0a7a44e05f628a58b7b1582820ed7814f0bcb289aad600b682c47d417aa43f8318354207b08912af
7
+ data.tar.gz: b663295e36441f53f769351676391de9660b01030c83783d05ff5b785b8093ee7f273e5156cf6b884ebc3015e49cd3b50935bfbedd58a3f6200a0615419e443f
@@ -0,0 +1,152 @@
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
+ x = 0
18
+
19
+ begin
20
+
21
+ x += 1
22
+
23
+ uri = URI.parse("http://api-clv.libring.com/v2/event_tracker")
24
+
25
+ https = Net::HTTP.new(uri.host, uri.port)
26
+ https.use_ssl = true
27
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
28
+
29
+ req = Net::HTTP::Post.new(uri.request_uri, initheader = {'Content-Type' =>'application/json', 'Authorization' => "Token #{@token}"})
30
+
31
+ req.set_form_data({ libring: { "#{contact.contact_code}" => { attributes: contact.attributes, location: contact.location, events: contact.events } }.to_json })
32
+
33
+ response = https.request(req)
34
+
35
+ if response.body == ""
36
+ { success: true }
37
+ else
38
+ { error: response.body, success: false }
39
+ end
40
+
41
+ rescue
42
+
43
+ if x <= 5
44
+ retry
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+
51
+ def get_contact(contact_code)
52
+
53
+ require "net/https"
54
+ require "uri"
55
+ require "json"
56
+
57
+ uri = URI.parse("http://api-clv.libring.com/v2/contact/get/" + contact_code.to_s)
58
+
59
+ https = Net::HTTP.new(uri.host, uri.port)
60
+ https.use_ssl = true
61
+
62
+ req = Net::HTTP::Get.new(uri.request_uri, initheader = {'Content-Type' =>'application/json', 'Authorization' => "Token #{@token}"})
63
+
64
+ resp = https.request(req)
65
+
66
+ resp.body
67
+
68
+ end
69
+
70
+ def update_attribute(contact_code, name, value, type)
71
+
72
+ require "net/https"
73
+ require "uri"
74
+ require "json"
75
+
76
+ uri = URI.parse("http://api-clv.libring.com/v2/contact/put")
77
+
78
+ https = Net::HTTP.new(uri.host, uri.port)
79
+ https.use_ssl = true
80
+
81
+ req = Net::HTTP::Post.new(uri.request_uri, initheader = {'Content-Type' =>'application/json', 'Authorization' => "Token #{@token}"})
82
+
83
+ req.set_form_data({libring: { "#{contact_code}"=> { "#{name}" => { value: "#{value}", type: "#{type}" } }}.to_json })
84
+
85
+ resp = https.request(req)
86
+
87
+ if resp.body == "OK"
88
+ { success: true }
89
+ else
90
+ { error: resp.body, success: false }
91
+ end
92
+
93
+ end
94
+
95
+ def get_message(contact_code)
96
+
97
+ require "net/https"
98
+ require "uri"
99
+ require "json"
100
+
101
+ uri = URI.parse("http://api-clv.libring.com/v2/messages/get/" + contact_code.to_s)
102
+
103
+ https = Net::HTTP.new(uri.host, uri.port)
104
+ https.use_ssl = true
105
+
106
+ req = Net::HTTP::Get.new(uri.request_uri, initheader = {'Content-Type' =>'application/json', 'Authorization' => "Token #{@token}"})
107
+
108
+ resp = https.request(req)
109
+
110
+ resp.body
111
+
112
+ end
113
+
114
+ def get_all_messages
115
+
116
+ require "net/https"
117
+ require "uri"
118
+ require "json"
119
+
120
+ uri = URI.parse("http://api-clv.libring.com/v2/messages/get_all")
121
+
122
+ https = Net::HTTP.new(uri.host, uri.port)
123
+ https.use_ssl = true
124
+
125
+ req = Net::HTTP::Get.new(uri.request_uri, initheader = {'Content-Type' =>'application/json', 'Authorization' => "Token #{@token}"})
126
+
127
+ resp = https.request(req)
128
+
129
+ resp.body
130
+
131
+ end
132
+
133
+ def get_clv(contact_code)
134
+
135
+ require "net/https"
136
+ require "uri"
137
+ require "json"
138
+
139
+ uri = URI.parse("http://api-clv.libring.com/v2/clv/get/" + contact_code.to_s)
140
+
141
+ https = Net::HTTP.new(uri.host, uri.port)
142
+ https.use_ssl = true
143
+
144
+ req = Net::HTTP::Get.new(uri.request_uri, initheader = {'Content-Type' =>'application/json', 'Authorization' => "Token #{@token}"})
145
+
146
+ resp = https.request(req)
147
+
148
+ resp.body
149
+
150
+ end
151
+
152
+ 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( { :event_type => event.event_type, :event_code => event.event_code, :source => event.source, :expire_at => event.expire_at, :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,150 @@
1
+ class Libring::Event
2
+
3
+ attr_reader :date, :source, :source_referral, :page_title, :ip, :expire_at, :invitees, :metadata, :products, :event_type, :event_code
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
+ @expire_at = ""
19
+ @event_type = ""
20
+ @event_code = ""
21
+
22
+ true
23
+
24
+ end
25
+
26
+ def set_event_type(data)
27
+
28
+ @event_type = data
29
+
30
+ true
31
+
32
+ end
33
+
34
+ def set_event_code(data)
35
+
36
+ @event_code = data
37
+
38
+ true
39
+
40
+ end
41
+
42
+ def set_expire_at(data)
43
+
44
+ @expire_at = data
45
+
46
+ true
47
+
48
+ end
49
+
50
+ def set_source(data)
51
+
52
+ @source = data
53
+
54
+ true
55
+
56
+ end
57
+
58
+ def set_source_referral(data)
59
+
60
+ @source_referral = data
61
+
62
+ true
63
+
64
+ end
65
+
66
+ def set_page_title(data)
67
+
68
+ @page_title = data
69
+
70
+ true
71
+
72
+ end
73
+
74
+ def set_ip(data)
75
+
76
+ 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)
77
+
78
+ @ip = data
79
+
80
+ true
81
+
82
+ else
83
+
84
+ "Invalid IP"
85
+
86
+ end
87
+
88
+ end
89
+
90
+ def add_invitee(name)
91
+
92
+ @invitees.push(name)
93
+
94
+ true
95
+
96
+ end
97
+
98
+ def clean_invitees
99
+
100
+ @invitees = []
101
+
102
+ true
103
+
104
+ end
105
+
106
+ def add_metadata(name, value)
107
+
108
+ @metadata[name] = value
109
+
110
+ true
111
+
112
+ end
113
+
114
+ def clean_metadata
115
+
116
+ @metadata = {}
117
+
118
+ true
119
+
120
+ end
121
+
122
+ def add_product(product)
123
+
124
+ if product.unit_amount != -1
125
+
126
+ @products["#{product.sku}"] = {}
127
+ @products["#{product.sku}"][:name] = product.name
128
+ @products["#{product.sku}"][:unit_amount] = product.unit_amount
129
+ @products["#{product.sku}"][:quantity] = product.quantity
130
+ @products["#{product.sku}"][:category] = product.category
131
+
132
+ true
133
+
134
+ else
135
+
136
+ "Product unit amount required"
137
+
138
+ end
139
+
140
+ end
141
+
142
+ def clean_products
143
+
144
+ @products = {}
145
+
146
+ true
147
+
148
+ end
149
+
150
+ end
@@ -0,0 +1,49 @@
1
+ class Libring::Product
2
+
3
+ attr_reader :sku, :name, :unit_amount, :quantity, :category
4
+
5
+ def initialize(sku)
6
+
7
+ @sku = sku
8
+ @name = sku
9
+ @quantity = 1
10
+ @unit_amount = -1
11
+ @category = ""
12
+
13
+ true
14
+
15
+ end
16
+
17
+ def set_name(data)
18
+
19
+ @name = data
20
+
21
+ true
22
+
23
+ end
24
+
25
+ def set_category(data)
26
+
27
+ @category = data
28
+
29
+ true
30
+
31
+ end
32
+
33
+ def set_unit_amount(data)
34
+
35
+ @unit_amount = data
36
+
37
+ true
38
+
39
+ end
40
+
41
+ def set_quantity(data)
42
+
43
+ @quantity = data
44
+
45
+ true
46
+
47
+ end
48
+
49
+ end
data/lib/libring.rb CHANGED
@@ -1,5 +1,11 @@
1
- Class Libring
2
- def self.hi
3
- puts "Hello world!"
1
+ class Libring
2
+
3
+ require 'libring/api'
4
+ require 'libring/contact'
5
+ require 'libring/event'
6
+ require 'libring/product'
7
+
8
+ def initialize()
4
9
  end
10
+
5
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libring
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vitor Pereira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-01 00:00:00.000000000 Z
11
+ date: 2016-02-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Libring API for Ruby
14
14
  email: vitor@libring.com
@@ -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