Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea
doc
.rvmrc
1 change: 1 addition & 0 deletions .rvmrc.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rvm use ruby-1.9.3@ruby-getresponse --create
2 changes: 1 addition & 1 deletion getresponse.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Gem::Specification.new do |s|
s.homepage = "http://dev.getresponse.com"
s.summary = "Ruby wrapper for GetResponse API"
s.description = "With this gem you can manage your subscribers, campaigns, messages"
s.version = "0.5"
s.version = "0.5.7"

s.add_dependency "json", "~> 1.4"
s.add_dependency "json_pure", "~>1.4"
Expand Down
4 changes: 3 additions & 1 deletion lib/get_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ module GetResponse
GetResponse.autoload :Conditions, "get_response/conditions"
GetResponse.autoload :LinksProxy, "get_response/links_proxy"
GetResponse.autoload :Link, "get_response/link"
GetResponse.autoload :Blacklist, "get_response/blacklist"
GetResponse.autoload :Blacklist, "get_response/blacklist"
GetResponse.autoload :Segment, "get_response/segment"
GetResponse.autoload :SegmentProxy, "get_response/segment_proxy"
26 changes: 18 additions & 8 deletions lib/get_response/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ module GetResponse

# Simple class that simulates connection to service
class Connection
API_URI = "http://api2.getresponse.com"
DEFAULT_API_URI = "http://api2.getresponse.com"

attr_reader :api_key

def initialize(api_key)
def initialize(api_key, api_url = nil)
@api_key = api_key
@api_url = api_url || DEFAULT_API_URI
end


Expand Down Expand Up @@ -46,6 +47,12 @@ def contacts
@contact_proxy ||= GetResponse::ContactProxy.new(self)
end

# Method returns proxy to execute all segment related operations.
#
# returns:: GetResponse::SegmentProxy
def segments
@segment_proxy ||= GetResponse::SegmentProxy.new(self)
end

# Method returns proxy to execute all message related operations.
#
Expand Down Expand Up @@ -76,15 +83,18 @@ def confirmation_subjects
# method:: String
#
# params:: Hash
def send_request(method, params = {})
def send_request(method, params = { })
request_params = {
:method => method,
:params => [@api_key, params]
jsonrpc: '2.0',
method: method,
params: [@api_key, params],
id: Time.now.to_i.to_s
}.to_json

uri = URI.parse(API_URI)
uri = URI.parse(@api_url)
path = ('' == uri.path) ? '/' : uri.path
resp = Net::HTTP.start(uri.host, uri.port) do |conn|
conn.post("/", request_params)
conn.post(path, request_params)
end
raise GetResponseError.new("API key verification failed") if resp.code.to_i == 403
response = JSON.parse(resp.body)
Expand All @@ -107,7 +117,7 @@ def links


def build_conditions(conditions)
conditions.inject({}) do |hash, cond|
conditions.inject({ }) do |hash, cond|
if cond[0].respond_to?(:evaluate)
hash.merge!(cond[0].evaluate(cond[1]))
else
Expand Down
7 changes: 6 additions & 1 deletion lib/get_response/message_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def initialize(connection)
#
# conditions:: Hash, empty by default
# returns:: Array of GetResponse::Message
def all(conditions = {})
def all(conditions = { })
response = @connection.send_request("get_messages", conditions)

response["result"].inject([]) do |messages, resp|
Expand All @@ -27,6 +27,11 @@ def all(conditions = {})
end
end

def send_newsletter(options)
response = @connection.send_request('send_newsletter', options)
Message.new({ 'id' => response['result']['MESSAGE_ID'] }, @connection)
end


protected

Expand Down
16 changes: 16 additions & 0 deletions lib/get_response/segment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module GetResponse

class Segment

attr_reader :id, :name, :created_on


def initialize(params)
@id = params['id']
@name = params['name']
@created_on = params['created_on']
end

end

end
19 changes: 19 additions & 0 deletions lib/get_response/segment_proxy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module GetResponse

class SegmentProxy

def initialize(connection)
@connection = connection
end

# Fetch all segments connected with account
#
# returns:: [Segment]
def all
segments_attrs = @connection.send_request('get_segments')['result']
segments_attrs.map do |id, attrs|
Segment.new(attrs.merge('id' => id))
end
end
end
end