yo-ruby 0.1.1 → 0.1.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 +8 -8
- data/lib/yo-ruby.rb +29 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MWJjNDhkOTI3NTA2MTA0NTA5YjA1MTU1YWZjZjI2ZTg3NmFkNzRkNQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
N2NlNDZiYWYyZTIxODQ3MjAxNjkwZjE4ZjgzM2RiYjc2MTI3Mzk4Ng==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZWQ5Y2Q3YTQyNzI1MzBiNjc5NzMyM2ZhZjBkYTAxMjhmZWNlNGZiMzg2ODBi
|
10
|
+
MTgzMmEyMDQzODA3YWI4ODZmMTk0ZmU3NmYyMjdjOTczNTBlOWViMWI0MjU4
|
11
|
+
ZGQ5OGExOTExYWNlMzYzYWYxNjg4ZGYwYjJiMDUxMTc1ZDFiMGY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MGMxNGYzMjdhYmQ4ODUxMmQ4NTAyNTgxNTYxZTI2ZDE0ZjlmMDEwOTUyYWY1
|
14
|
+
MjE0NDNhMWVhMTc5Mzc5NTJkMmU5ODgxZjI4OWY3MjMyNmNjMmMyNzg5MDFi
|
15
|
+
ZTk4MTIwNDRlN2MxYzQzYzFmYWNjZGVhNWU1YzllYTgwY2VjODA=
|
data/lib/yo-ruby.rb
CHANGED
@@ -4,6 +4,12 @@ require 'httparty'
|
|
4
4
|
class YoException < Exception
|
5
5
|
end
|
6
6
|
|
7
|
+
class YoUserNotFound < YoException
|
8
|
+
end
|
9
|
+
|
10
|
+
class YoRateLimitExceeded < YoException
|
11
|
+
end
|
12
|
+
|
7
13
|
class Yo
|
8
14
|
include Singleton
|
9
15
|
include HTTParty
|
@@ -31,20 +37,20 @@ class Yo
|
|
31
37
|
end
|
32
38
|
|
33
39
|
# Yo calls.
|
34
|
-
def self.yo(username)
|
35
|
-
self.__post('/yo/', { :username => username })["result"] == "OK"
|
40
|
+
def self.yo(username, extra_params = {})
|
41
|
+
self.__post('/yo/', { :username => username }.merge(extra_params))["result"] == "OK"
|
36
42
|
end
|
37
43
|
|
38
|
-
def self.yo!(username)
|
39
|
-
self.yo(username)
|
44
|
+
def self.yo!(username, extra_params = {})
|
45
|
+
self.yo(username, extra_params)
|
40
46
|
end
|
41
47
|
|
42
|
-
def self.all
|
43
|
-
self.__post('/yoall/')["result"] == "OK"
|
48
|
+
def self.all(extra_params = {})
|
49
|
+
self.__post('/yoall/', extra_params)["result"] == "OK"
|
44
50
|
end
|
45
51
|
|
46
|
-
def self.all!
|
47
|
-
self.all
|
52
|
+
def self.all!(extra_params = {})
|
53
|
+
self.all(extra_params)
|
48
54
|
end
|
49
55
|
|
50
56
|
def self.subscribers
|
@@ -58,12 +64,14 @@ class Yo
|
|
58
64
|
# Receive a yo.
|
59
65
|
def self.receive(params)
|
60
66
|
parameters = __clean(params)
|
61
|
-
|
67
|
+
link = parameters.keys.include?(:link) ? parameters[:link] : nil
|
68
|
+
yield(parameters[:username].to_s, link) if parameters.keys.length > 0 and parameters.include?(:username)
|
62
69
|
end
|
63
70
|
|
64
71
|
def self.from(params, username)
|
65
72
|
parameters = __clean(params)
|
66
|
-
|
73
|
+
link = parameters.keys.include?(:link) ? parameters[:link] : nil
|
74
|
+
yield(link) if parameters.keys.length > 0 and parameters.include?(:username) and params[:username].to_s.upcase == username.upcase
|
67
75
|
end
|
68
76
|
|
69
77
|
# Private methods.
|
@@ -77,11 +85,18 @@ class Yo
|
|
77
85
|
end
|
78
86
|
|
79
87
|
def self.__parse(res)
|
80
|
-
|
81
|
-
|
88
|
+
begin
|
89
|
+
if res.parsed_response.keys.include?("error") or res.parsed_response["code"] == 141
|
90
|
+
raise YoUserNotFound.new("You cannot Yo yourself and/or your developer Yo usernames. Why? Ask Or Arbel, CEO of Yo - or@justyo.co") if res.parsed_response["error"][0..8] == "TypeError"
|
91
|
+
raise YoUserNotFound.new(res.parsed_response["error"])
|
92
|
+
end
|
93
|
+
|
94
|
+
return res.parsed_response
|
95
|
+
rescue NoMethodError => e
|
96
|
+
raise YoRateLimitExceeded.new(res.parsed_response)
|
97
|
+
rescue JSON::ParserError => e
|
98
|
+
raise YoException.new(e)
|
82
99
|
end
|
83
|
-
|
84
|
-
res.parsed_response
|
85
100
|
end
|
86
101
|
|
87
102
|
def self.__clean(hash)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yo-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bilawal Hameed
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|