Class: BoxcarPublisher::Push

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Push

Returns a new instance of Push.



38
39
40
41
42
# File 'lib/boxcar_publisher.rb', line 38

def initialize options
  result = BoxcarPublisher._conn.post 'push', options
  @id = result.body['ok']
  @url = result.headers['Location']
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



36
37
38
# File 'lib/boxcar_publisher.rb', line 36

def id
  @id
end

#urlObject

Returns the value of attribute url.



36
37
38
# File 'lib/boxcar_publisher.rb', line 36

def url
  @url
end

Instance Method Details

#deleteObject



55
56
57
58
# File 'lib/boxcar_publisher.rb', line 55

def delete
  result = BoxcarPublisher._conn.delete "push/#{id}"
  raise "Expected repsonse to have HTTP status 202, received #{result.status}" unless result.status == 202
end

#stateObject



44
45
46
47
48
49
50
51
52
53
# File 'lib/boxcar_publisher.rb', line 44

def state
  result = BoxcarPublisher._conn.get "push/#{id}"
  json = result.body
  {}.tap do |res|
    json.each do |key, value|
      value = (DateTime.parse(value).to_time rescue value) if key =~ /_at\z/
      res[key.to_sym] = value
    end
  end
end