Class: Myrando::MyRando
Defined Under Namespace
Classes: ApiError, InvalidParameterError
Instance Attribute Summary collapse
-
#user_info ⇒ Object
Returns the value of attribute user_info.
Instance Method Summary collapse
- #get_account_status ⇒ Object
- #get_photos(page = 1) ⇒ Object
-
#initialize(options = {}) ⇒ MyRando
constructor
A new instance of MyRando.
Constructor Details
#initialize(options = {}) ⇒ MyRando
Returns a new instance of MyRando.
33 34 35 36 37 38 39 40 |
# File 'lib/myrando.rb', line 33 def initialize( = {}) username = [:username].to_uri if [:username].kind_of?(String) password = [:password].to_uri if [:password].kind_of?(String) raise InvalidParameterError, "MyRando must :username attribute" if username.nil? raise InvalidParameterError, "MyRando must :password attribute" if password.nil? @connection = RandoConnection.new() @user_info = login(username, password) end |
Instance Attribute Details
#user_info ⇒ Object
Returns the value of attribute user_info.
31 32 33 |
# File 'lib/myrando.rb', line 31 def user_info @user_info end |
Instance Method Details
#get_account_status ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/myrando.rb', line 61 def get_account_status() resp = @connection.get("#{RANDO_API_URL}/account.json?auth_token=#{@user_info[:token]}") if resp.code == 200 begin json = MultiJson.decode(resp.body) raise ApiError, "Rando returned an error: #{json['error']}" if json.has_key?('error') return json rescue MultiJson::DecodeError raise ApiError, "Rando returned an error:\nStatus: #{resp.code}\nBody: #{resp.body}" end else raise ApiError, "Rando returned an error:\nStatus: #{resp.code}\nBody: #{resp.body}" end end |
#get_photos(page = 1) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/myrando.rb', line 42 def get_photos(page=1) resp = @connection.get("#{RANDO_API_URL}/users/#{@user_info[:user_id]}/deliveries/received.json?page=#{page}&auth_token=#{@user_info[:token]}") if resp.code == 200 begin json = MultiJson.decode(resp.body) raise ApiError, "Rando returned an error: #{json['error']}" if not json.kind_of?(Array) and json.has_key?('error') randos = [] json.each do |r| randos << r end randos rescue MultiJson::DecodeError raise ApiError, "Rando returned an error:\nStatus: #{resp.code}\nBody: #{resp.body}" end else raise ApiError, "Rando returned an error:\nStatus: #{resp.code}\nBody: #{resp.body}" end end |