Class: Timepad::Base
- Inherits:
-
Object
show all
- Defined in:
- lib/timepad/base.rb
Instance Method Summary
collapse
Instance Method Details
#make_query(params) ⇒ Object
12
13
14
|
# File 'lib/timepad/base.rb', line 12
def make_query(params)
params.map{|key, value| value.nil? ? "" : "#{key}=#{URI::encode value.to_s}"}.join('&')
end
|
#make_uri(action, params = {}) ⇒ Object
16
17
18
19
20
21
|
# File 'lib/timepad/base.rb', line 16
def make_uri(action, params = {})
params.merge!({'id' => @client.id, 'code' => @client.key})
query = make_query(params)
object = self.class.name.split('::').last.downcase
URI("#{Timepad.endpoint.downcase}#{object}_#{action}?#{query}")
end
|
#request(action, params = {}) ⇒ Object
6
7
8
9
10
|
# File 'lib/timepad/base.rb', line 6
def request(action, params = {})
uri = make_uri(action, params)
response = Net::HTTP.get(uri)
JSON.parse(response)
end
|
#subscribers_to_hash(subscribers) ⇒ Hash
Convert Array of Hash to Hash
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/timepad/base.rb', line 27
def subscribers_to_hash(subscribers)
i = 0
params = {}
subscribers.each do |subscriber|
next if subscriber[:email].empty?
%w(email name surnname middlename company phone comment).each do |key|
if subscriber[key.to_sym]
params[ "i#{i}_#{key}".to_sym ] = subscriber[key.to_sym]
end
end
i += 1
end
params
end
|