Class: SendHub

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/ruby-sendhub.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key = nil, number = nil) ⇒ SendHub

Returns a new instance of SendHub.



12
13
14
15
# File 'lib/ruby-sendhub.rb', line 12

def initialize(api_key = nil, number = nil)
	@number = number
	@api_key = api_key
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, hsh = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ruby-sendhub.rb', line 17

def method_missing(method, hsh = {})
	meth = method.to_s.split("_")
	if meth.first == "put" || meth.first == "delete"
		if meth.last == "messages"
			api_url = base_url + meth.last + "/" + hsh[:id].to_s + credentials
			hsh.delete(:id)
		else
			api_url = base_url + meth.last + "/" + hsh[:id].to_s + credentials
		end
	elsif meth.first == "get" && (meth.last == "threads" || meth.last == "messages" || !hsh[:id].nil?)
		api_url = base_url + meth.last + "/" + hsh[:id].to_s + credentials
	else
		api_url = base_url + meth.last + credentials
	end
	ret = send_request(meth.first, api_url, :body => hsh.to_json)
	ret.nil? && meth.first == "delete" ? "Aaaand it's gone" : ret
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



8
9
10
# File 'lib/ruby-sendhub.rb', line 8

def api_key
  @api_key
end

#numberObject

Returns the value of attribute number.



8
9
10
# File 'lib/ruby-sendhub.rb', line 8

def number
  @number
end

Instance Method Details

#get_groups_contacts(hsh = {}) ⇒ Object



35
36
37
# File 'lib/ruby-sendhub.rb', line 35

def get_groups_contacts(hsh = {})
	send_request("get", group_contacts_url(hsh), :body => hsh.to_json)
end

#post_groups_contacts(hsh = {}) ⇒ Object



39
40
41
# File 'lib/ruby-sendhub.rb', line 39

def post_groups_contacts(hsh = {})
	send_request("post", group_contacts_url(hsh), :body => hsh.to_json)
end