myrando 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/myrando.rb +25 -4
- data/lib/myrando/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aec93bf83dd5b45641e4e960702fe6db107ebce1
|
4
|
+
data.tar.gz: b9af4f76673353de8ab2d6172ce2693ade57f8eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f35ebf916baa714adbcd9596a765672c6586397c3fe6d86f962a8428e8e23ccdca1f180471b105f1bc9d793f2a33f7a694d4fb9553f8d3e348232602b37c1d5
|
7
|
+
data.tar.gz: ae01d3b534bcf28912a9f986bc68092222fc955ef9e1f4254edd573e1dfc37aa7ac877c1de1888a20aef30ee8a216dfe0c86df5866106c8a82d1f0f1e73c5987
|
data/lib/myrando.rb
CHANGED
@@ -6,10 +6,28 @@ require "uri-handler"
|
|
6
6
|
module Myrando
|
7
7
|
RANDO_API_URL = "http://rando.ustwo.se"
|
8
8
|
|
9
|
+
class RandoConnection
|
10
|
+
include HTTParty
|
11
|
+
|
12
|
+
def initialize()
|
13
|
+
end
|
14
|
+
|
15
|
+
def get(path)
|
16
|
+
opts = { :headers => { 'User-Agent' => "myrando/#{Myrando::VERSION}" } }
|
17
|
+
return self.class.get(path, opts)
|
18
|
+
end
|
19
|
+
|
20
|
+
def post(path, body)
|
21
|
+
opts = { :body => body, :headers => { 'User-Agent' => "myrando/#{Myrando::VERSION}" } }
|
22
|
+
return self.class.post(path, opts)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
9
26
|
class MyRando
|
10
27
|
include HTTParty
|
11
28
|
class InvalidParameterError < StandardError; end
|
12
29
|
class ApiError < StandardError; end
|
30
|
+
|
13
31
|
attr_accessor :user_info
|
14
32
|
|
15
33
|
def initialize(options = {})
|
@@ -17,11 +35,12 @@ module Myrando
|
|
17
35
|
password = options[:password].to_uri if options [:password].kind_of?(String)
|
18
36
|
raise InvalidParameterError, "MyRando must :username attribute" if username.nil?
|
19
37
|
raise InvalidParameterError, "MyRando must :password attribute" if password.nil?
|
38
|
+
@connection = RandoConnection.new()
|
20
39
|
@user_info = login(username, password)
|
21
40
|
end
|
22
41
|
|
23
42
|
def get_photos(page=1)
|
24
|
-
resp =
|
43
|
+
resp = @connection.get("#{RANDO_API_URL}/users/#{@user_info[:user_id]}/deliveries/received.json?page=#{page}&auth_token=#{@user_info[:token]}")
|
25
44
|
if resp.code == 200
|
26
45
|
begin
|
27
46
|
json = MultiJson.decode(resp.body)
|
@@ -40,7 +59,7 @@ module Myrando
|
|
40
59
|
end
|
41
60
|
|
42
61
|
def get_account_status()
|
43
|
-
resp =
|
62
|
+
resp = @connection.get("#{RANDO_API_URL}/account.json?auth_token=#{@user_info[:token]}")
|
44
63
|
if resp.code == 200
|
45
64
|
begin
|
46
65
|
json = MultiJson.decode(resp.body)
|
@@ -57,15 +76,17 @@ module Myrando
|
|
57
76
|
private
|
58
77
|
def login(username, password)
|
59
78
|
body = "user[email]=#{username}&user[password]=#{password}"
|
60
|
-
resp =
|
79
|
+
resp = @connection.post("#{RANDO_API_URL}/users/sign_in.json", body)
|
61
80
|
if resp.code == 200
|
62
81
|
begin
|
63
82
|
json = MultiJson.decode(resp.body)
|
64
83
|
raise ApiError, "Rando returned an error: #{json['error']}" if json.has_key?('error')
|
65
84
|
{:token => json['authentication_token'], :user_id => json['id']}
|
66
85
|
rescue MultiJson::DecodeError
|
67
|
-
raise ApiError, "
|
86
|
+
raise ApiError, "Error decoding Rando answer"
|
68
87
|
end
|
88
|
+
else
|
89
|
+
raise ApiError, "Rando return an error: \nStatus: #{resp.code}\n"
|
69
90
|
end
|
70
91
|
end
|
71
92
|
|
data/lib/myrando/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: myrando
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ómar Kjartan Yasin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
115
|
version: '0'
|
116
116
|
requirements: []
|
117
117
|
rubyforge_project:
|
118
|
-
rubygems_version: 2.0.
|
118
|
+
rubygems_version: 2.0.3
|
119
119
|
signing_key:
|
120
120
|
specification_version: 4
|
121
121
|
summary: Interact with the Rando API
|