Class: WhatCounts::HttpClient

Inherits:
Object
  • Object
show all
Defined in:
lib/whatcounts/http_client.rb

Defined Under Namespace

Classes: Config, InvalidConfiguration

Constant Summary collapse

VALID_COMMANDS =
[:subscribe,:update,:change,:unsubscribe,:delete,:find,
:findinlist,:details,:createlist,:show_lists,:createseg,:show_seg,
:update_seg,:delete_seg,:createtemplate,:show_templates,:updatetemplate,
:show_user_events,:show_optout,:show_optglobal,:show_hard,:show_soft,
:send,:launch,:show_campaigns,:show_campaign_stats,:show_campaign_stats_multi]

Class Method Summary collapse

Class Method Details

.configure(&block) ⇒ Object

Configure the client Example:

WhatCounts::HttpClient.configure do

api_url  "http://example.com"
realm    "client-realm"
password "superdupersecret"

end



21
22
23
24
25
# File 'lib/whatcounts/http_client.rb', line 21

def configure(&block)
  @config = Config.new
  @config.instance_eval(&block)
  @config
end

.execute(command, requestable) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/whatcounts/http_client.rb', line 27

def execute(command,requestable)
  raise InvalidConfiguration,"Invalid WhatCounts configuration, are you sure it was configured?" unless @config
  request_string = requestable.kind_of?(String) ? requestable : requestable.to_param_string
  url = [@config.api_url,"?","c=#{command}&",@config.to_param_string,"&",request_string].join
  res = Curl::Easy.perform(url) do |easy|
    easy.connect_timeout = 10
    easy.timeout = 30
  end
  WhatCounts::Response.new(url,res.body_str)
end