Class: GetResponse::Connection
- Inherits:
-
Object
- Object
- GetResponse::Connection
- Defined in:
- lib/get_response/connection.rb
Overview
Simple class that simulates connection to service
Constant Summary collapse
- API_URI =
"http://api2.getresponse.com"
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
Instance Method Summary collapse
-
#account ⇒ Object
Get basic info about your account.
-
#campaigns ⇒ Object
Method returns proxy to execute all campaign related operations.
-
#confirmation_bodies ⇒ ConfirmationBodyProxy
Method returnx proxy to execute all confirmation body related operations.
-
#confirmation_subjects ⇒ ConfirmationSubjectProxy
Method returnx proxy to execute all confirmation subject related operations.
-
#contacts ⇒ Object
Method returns proxy to execute all contact related operations.
-
#initialize(api_key) ⇒ Connection
constructor
A new instance of Connection.
-
#messages ⇒ Object
Method returns proxy to execute all message related operations.
-
#ping ⇒ Object
Test connection with API.
-
#send_request(method, params = {}) ⇒ Object
Send request to JSON-RPC service.
Constructor Details
#initialize(api_key) ⇒ Connection
Returns a new instance of Connection.
11 12 13 |
# File 'lib/get_response/connection.rb', line 11 def initialize(api_key) @api_key = api_key end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
9 10 11 |
# File 'lib/get_response/connection.rb', line 9 def api_key @api_key end |
Instance Method Details
#account ⇒ Object
Get basic info about your account.
- returns
-
GetResponse::Account
28 29 30 31 |
# File 'lib/get_response/connection.rb', line 28 def account resp = self.send_request("get_account_info") GetResponse::Account.new(resp["result"], self) end |
#campaigns ⇒ Object
Method returns proxy to execute all campaign related operations.
- returns
-
GetResponse::CampaignProxy
37 38 39 |
# File 'lib/get_response/connection.rb', line 37 def campaigns @campaign_proxy ||= GetResponse::CampaignProxy.new(self) end |
#confirmation_bodies ⇒ ConfirmationBodyProxy
Method returnx proxy to execute all confirmation body related operations.
61 62 63 |
# File 'lib/get_response/connection.rb', line 61 def confirmation_bodies @confirmation_body_proxy ||= GetResponse::ConfirmationBodyProxy.new(self) end |
#confirmation_subjects ⇒ ConfirmationSubjectProxy
Method returnx proxy to execute all confirmation subject related operations.
69 70 71 |
# File 'lib/get_response/connection.rb', line 69 def confirmation_subjects @confirmation_subject_proxy ||= GetResponse::ConfirmationSubjectProxy.new(self) end |
#contacts ⇒ Object
Method returns proxy to execute all contact related operations.
- returns
-
GetResponse::ContactProxy
45 46 47 |
# File 'lib/get_response/connection.rb', line 45 def contacts @contact_proxy ||= GetResponse::ContactProxy.new(self) end |
#messages ⇒ Object
Method returns proxy to execute all message related operations.
- returns
-
GetResponse::MessageProxy
53 54 55 |
# File 'lib/get_response/connection.rb', line 53 def @message_proxy ||= GetResponse::MessageProxy.new(self) end |
#ping ⇒ Object
Test connection with API.
- returns
-
Boolean
19 20 21 22 |
# File 'lib/get_response/connection.rb', line 19 def ping result = self.send_request("ping") return result["errors"].nil? end |
#send_request(method, params = {}) ⇒ Object
Send request to JSON-RPC service.
- method
-
String
- params
-
Hash
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/get_response/connection.rb', line 79 def send_request(method, params = {}) request_params = { :method => method, :params => [@api_key, params] }.to_json uri = URI.parse(API_URI) resp = Net::HTTP.start(uri.host, uri.port) do |conn| conn.post("/", request_params) end raise GetResponseError.new("API key verification failed") if resp.code.to_i == 403 response = JSON.parse(resp.body) if response["error"] raise GetResponse::GetResponseError.new(response["error"]) end response end |