yo-ruby 0.1.0
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 +15 -0
- data/lib/yo-ruby.rb +92 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NTI0MTljNzU3MTAyMTgwYmM2ODdjMTIwYjU0NTMxNzhmYWU3NzY2Mw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZmZkZmZiN2E4NTBhNWE2YTNhMmM4NzlmZmMwZjAyMGEwZTg3MDExYw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
Y2FlMTI5NWZiMmU2MTBjYTJkYjk5NmU5Yzk3ZWFkNmYzYWIxNDRmMTczNzI1
|
10
|
+
YzVhYTA5YmJhNGEyYjMxZTUwOTE4MDA0ZTY1ZWUyZGZkMmEwMmVjZWIyM2Nl
|
11
|
+
Mjk5Y2Y4OGZjYzgwNmFhZmU4NmY2ZDE4YzQxZmU5NDM3NTZhNGE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ODBhNDViZWQyMjQ1YmY0NWU5N2I3ZWY3OGQyNGUzZGJhYjFiMDVkNWVlOGI4
|
14
|
+
NmJjMGJhY2NmMzUzYmQ1ZDgyZTVlMTAzZmM0MjNlYzJmYzc2ZWNhYjc4ODkw
|
15
|
+
ZTEwYjg2MWM3ZDU1NjI3ZGU0YTg0MzRiNDE2NjFmM2U2ZTUwMzE=
|
data/lib/yo-ruby.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'httparty'
|
3
|
+
|
4
|
+
class YoException < Exception
|
5
|
+
end
|
6
|
+
|
7
|
+
class Yo
|
8
|
+
include Singleton
|
9
|
+
include HTTParty
|
10
|
+
|
11
|
+
base_uri "api.justyo.co"
|
12
|
+
format :json
|
13
|
+
|
14
|
+
attr_writer :api_key
|
15
|
+
|
16
|
+
# Authentication stuffs.
|
17
|
+
def self.api_key
|
18
|
+
@api_key
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.api_key?
|
22
|
+
not @api_key.nil?
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.api_key=(api_key)
|
26
|
+
if api_key.to_s.length != 36 or not api_key.is_a?(String)
|
27
|
+
raise YoException.new("Invalid Yo API key - must be 36 characters in length")
|
28
|
+
end
|
29
|
+
|
30
|
+
@api_key = api_key
|
31
|
+
end
|
32
|
+
|
33
|
+
# Yo calls.
|
34
|
+
def self.yo(username)
|
35
|
+
self.__post('/yo/', { :username => username })["result"] == "OK"
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.yo!(username)
|
39
|
+
self.yo(username)
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.all
|
43
|
+
self.__post('/yoall/')["result"] == "OK"
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.all!
|
47
|
+
self.all
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.subscribers
|
51
|
+
self.__get('/subscribers_count/')["result"].to_i
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.subscribers?
|
55
|
+
self.subscribers > 0
|
56
|
+
end
|
57
|
+
|
58
|
+
# Receive a yo.
|
59
|
+
def self.receive(params)
|
60
|
+
parameters = __clean(params)
|
61
|
+
yield(parameters[:username].to_s) if parameters.keys.length > 0 and parameters.include?(:username)
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.from(params, username)
|
65
|
+
parameters = __clean(params)
|
66
|
+
yield if parameters.keys.length > 0 and parameters.include?(:username)
|
67
|
+
end
|
68
|
+
|
69
|
+
# Private methods.
|
70
|
+
private
|
71
|
+
def self.__post(endpoint, params = {})
|
72
|
+
__parse(post(endpoint, { body: params.merge(api_token: @api_key) }))
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.__get(endpoint, params = {})
|
76
|
+
__parse(get(endpoint, { query: params.merge(api_token: @api_key) }))
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.__parse(res)
|
80
|
+
if res.parsed_response.keys.include?("error") or res.parsed_response["code"] == 141
|
81
|
+
raise YoException.new(res.parsed_response["error"])
|
82
|
+
end
|
83
|
+
|
84
|
+
res.parsed_response
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.__clean(hash)
|
88
|
+
new_hash = {}
|
89
|
+
hash.each { |k, v| new_hash[k.to_sym] = v } if hash.is_a?(Hash)
|
90
|
+
new_hash
|
91
|
+
end
|
92
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yo-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bilawal Hameed
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-22 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Probably the most complex Ruby wrapper for the Yo app (justyo.co) that
|
14
|
+
recently raised $1 million dollars.
|
15
|
+
email: bilawal@studenthack.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/yo-ruby.rb
|
21
|
+
homepage: http://github.com/bih/yo-ruby
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.1.9
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: An awesome Ruby wrapper for the Yo! mobile app.
|
45
|
+
test_files: []
|
46
|
+
has_rdoc:
|