Class: FlickrResponse

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

Overview

This class encapusulates Flickr’s JSON response block. Error code and error messsage are read from the response block. This class is intended to be simple and minimalistic, since the data body can be extracted very easily.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ FlickrResponse

Initializes the instance with reponse block data



24
25
26
# File 'lib/objectiveflickr/flickr_response.rb', line 24

def initialize(response)
  @data = JSON.parse(response)
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



21
22
23
# File 'lib/objectiveflickr/flickr_response.rb', line 21

def data
  @data
end

Instance Method Details

#[](x) ⇒ Object

A quick accessor to the data block



49
50
51
# File 'lib/objectiveflickr/flickr_response.rb', line 49

def [](x)
  @data[x]
end

#error?Boolean

Returns true if there’s something wrong with the method call

Returns:

  • (Boolean)


34
35
36
# File 'lib/objectiveflickr/flickr_response.rb', line 34

def error?
  return !ok?
end

#error_codeObject

Returns Flickr’s error code, 0 if none



39
40
41
# File 'lib/objectiveflickr/flickr_response.rb', line 39

def error_code
  @data["code"] || 0
end

#error_messageObject

Returns Flickr error message, nil if none



44
45
46
# File 'lib/objectiveflickr/flickr_response.rb', line 44

def error_message
  @data["message"]
end

#ok?Boolean

Returns true if it’s a valid Flickr response

Returns:

  • (Boolean)


29
30
31
# File 'lib/objectiveflickr/flickr_response.rb', line 29

def ok?
  return @data["stat"] == "ok" ? true : false
end