Class: EepClient

Inherits:
Object
  • Object
show all
Defined in:
lib/eep_client.rb,
lib/eep_client/const.rb,
lib/eep_client/response.rb

Defined Under Namespace

Modules: Const Classes: ErrorResponse, OkResponse, Response

Instance Method Summary collapse

Constructor Details

#initialize(api_token, options = { }) ⇒ EepClient

Returns a new instance of EepClient.



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/eep_client.rb', line 32

def initialize(api_token, options = { })
  @api_token = api_token
  @debug = options[:debug]
  @base_url = options[:base_url] || BASE_URL
  
  unless options[:no_send]
    uri = URI(@base_url)      
    @http = Net::HTTP.new(uri.host, uri.port)
    @http.use_ssl = true
    @http.verify_mode = OpenSSL::SSL::VERIFY_NONE if options[:no_verify]
    @http.set_debug_output($stdout) if @debug
  end
end

Instance Method Details

#send_clear(clear) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/eep_client.rb', line 65

def send_clear(clear)
  json = format_clear(clear)
  if @debug
    puts "sending clear json:"
    puts json
  end
  if @http
    headers = { ACC_HDR => APP_JSON, CON_HDR => APP_JSON }
    res = @http.send_request(POST, CLEAR_RESOURCE, json, headers)
    if res.is_a? Net::HTTPServerError
      res.error!
    else      
      Response.new_instance(JSON.parse(res.body))
    end
  else
    Response.mock_clear_ok      
  end
end

#send_event(event) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/eep_client.rb', line 46

def send_event(event)
  json = format_event(event)
  if @debug
    puts "sending event json:"
    puts json
  end
  if @http
    headers = { ACC_HDR => APP_JSON, CON_HDR => APP_JSON }      
    res = @http.send_request(POST, EVENT_RESOURCE, json, headers)
    if res.is_a? Net::HTTPServerError
      res.error!
    else
      Response.new_instance(JSON.parse(res.body))
    end
  else
    Response.mock_event_ok
  end
end