myrando 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c560dd94f8e95acb9c5a40e2afb3606b9a5e536a
4
- data.tar.gz: fd9ad2c5bcd8efe14c13fbcb8e9a4714d44db1b1
3
+ metadata.gz: 342b4b10703690ed8fef14bfa4cacbde22fc63b5
4
+ data.tar.gz: b0ba567316d220050090178010398c4e91732e86
5
5
  SHA512:
6
- metadata.gz: 1119a887c59fe6642e720f71f79a51e9019ef36cdd809febed1ecd31c0de0df14ecea1c5decb93c089b9804b7e8000ecd5650df62dd7499f9f804272f49acf54
7
- data.tar.gz: fb8b7118cbd064c2878d1d0eae44567c45f8168675ec6f08142dee2dbd7e2c42da81ff307532848320afbc527d69b1d46b7db4f73fdf2a651414922ff5bee714
6
+ metadata.gz: 28aaa1a0a44fa80c34ed17d8882fafa85465de1e6e16c6a9744bd3eda9ff9d8d32c1e19c9b6e9a51e477cd33a56e5f9cab49e7e1adfffd4afe28c06aee540750
7
+ data.tar.gz: 337a3e1e2e201f34c6985586b1181511bb9559539115392c78751d1dbcf716121b7d17a4f6922a26850c191fe65385f6825250b5d80a07fcad2ed4dae3cf063e
data/README.md CHANGED
@@ -26,6 +26,14 @@ rando = Myrando::MyRando.new(:username => "your email", :password => "your passw
26
26
  rando.get_photos()
27
27
  ```
28
28
 
29
+ ### Get your account status
30
+
31
+ ``` ruby
32
+ require 'myrando'
33
+ rando = Myrando::MyRando.new(:username => "your email", :password => "your password")
34
+ rando.get_account_status()
35
+ ```
36
+
29
37
  ## Contributing
30
38
 
31
39
  1. Fork it
@@ -1,3 +1,3 @@
1
1
  module Myrando
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/myrando.rb CHANGED
@@ -23,12 +23,34 @@ module Myrando
23
23
  def get_photos(page=1)
24
24
  resp = self.class.get("#{RANDO_API_URL}/users/#{@user_info[:user_id]}/deliveries/received.json?page=#{page}&auth_token=#{@user_info[:token]}")
25
25
  if resp.code == 200
26
- json = MultiJson.decode(resp.body)
27
- randos = []
28
- json.each do |r|
29
- randos << r
26
+ begin
27
+ json = MultiJson.decode(resp.body)
28
+ raise ApiError, "Rando returned an error: #{json['error']}" if not json.kind_of?(Array) and json.has_key?('error')
29
+ randos = []
30
+ json.each do |r|
31
+ randos << r
32
+ end
33
+ randos
34
+ rescue MultiJson::DecodeError
35
+ raise ApiError, "Rando returned an error:\nStatus: #{resp.code}\nBody: #{resp.body}"
36
+ end
37
+ else
38
+ raise ApiError, "Rando returned an error:\nStatus: #{resp.code}\nBody: #{resp.body}"
39
+ end
40
+ end
41
+
42
+ def get_account_status()
43
+ resp = self.class.get("#{RANDO_API_URL}/account.json?auth_token=#{@user_info[:token]}")
44
+ if resp.code == 200
45
+ begin
46
+ json = MultiJson.decode(resp.body)
47
+ raise ApiError, "Rando returned an error: #{json['error']}" if json.has_key?('error')
48
+ return json
49
+ rescue MultiJson::DecodeError
50
+ raise ApiError, "Rando returned an error:\nStatus: #{resp.code}\nBody: #{resp.body}"
30
51
  end
31
- randos
52
+ else
53
+ raise ApiError, "Rando returned an error:\nStatus: #{resp.code}\nBody: #{resp.body}"
32
54
  end
33
55
  end
34
56
 
@@ -39,7 +61,7 @@ module Myrando
39
61
  if resp.code == 200
40
62
  begin
41
63
  json = MultiJson.decode(resp.body)
42
- raise ApiError, "Rando returned an error: #{json['error']}" if json['error']
64
+ raise ApiError, "Rando returned an error: #{json['error']}" if json.has_key?('error')
43
65
  {:token => json['authentication_token'], :user_id => json['id']}
44
66
  rescue MultiJson::DecodeError
45
67
  raise ApiError, "Rando returned an error:\nStatus: #{resp.code}\nBody: #{resp.body}"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: myrando
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ómar Kjartan Yasin