hey 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +13 -2
- data/Rakefile +8 -0
- data/lib/hey.rb +1 -0
- data/lib/hey/version.rb +1 -1
- data/lib/hey/yo.rb +47 -4
- data/test/yo_test.rb +17 -4
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZmY2YmFlMzU2NzVlZjJmNTA0ODZmODFhMzg4YmE5MjNlMGJhZmZiYg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
Yjk4MWVjYzJjZmUyZDIyOTMyNDhkMmIwZTNiNWFlNDQxNmQ1OWU2OQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YzA2NzQwNTRkZWY0M2FhNGJiODk1MjQzYTFjZWNmNmE4ZTE2ZWFiZjIxNzhk
|
10
|
+
OGMzM2VkZmYzMmRhYWFlZDFiYjYzN2IxYTkyNmM0MjQ3MDIwMGI5MDE3YmVm
|
11
|
+
OWRjMWI0NzBkNzZkNGE2YzdjOWI4YWY3YmQxNDkzMDQyZDhkY2Q=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
N2EyOTY0YjlkMGI5OWIzZjUwNjRmMmRmYWEwZTIzNWYyM2VjYjgzZDgzZWNl
|
14
|
+
ZTk0NzYyM2M4NmQxMDYyMTliYWU1MGJjYjNmMjAyMWNkOWM5ZWQ4OWYwMjky
|
15
|
+
MzA5YWQ0MWFhNmZkYmI0NTA1ZWQ1NDMxOTZiNGFkZmE3ODAxZGQ=
|
data/README.md
CHANGED
@@ -4,6 +4,8 @@ A Ruby library for sending yo's from [Yo](http://justyo.co).
|
|
4
4
|
|
5
5
|
[github.com/jackjennings/hey](http://github.com/jackjennings/hey)
|
6
6
|
|
7
|
+
[![Gem Version](https://badge.fury.io/rb/hey.svg)](http://badge.fury.io/rb/hey) [![Code Climate](https://codeclimate.com/github/jackjennings/hey.png)](https://codeclimate.com/github/jackjennings/hey) [![Build Status](https://travis-ci.org/jackjennings/hey.svg)](https://travis-ci.org/jackjennings/hey)
|
8
|
+
|
7
9
|
# Installation
|
8
10
|
|
9
11
|
```
|
@@ -12,13 +14,22 @@ gem install hey
|
|
12
14
|
|
13
15
|
# Usage
|
14
16
|
|
17
|
+
First [get an API token](http://yoapi.justyo.co).
|
18
|
+
|
19
|
+
Then:
|
20
|
+
|
15
21
|
```ruby
|
16
22
|
Hey.api_token = '3858f62230ac3c915f300c664312c63f'
|
17
23
|
Hey::Yo.all
|
18
24
|
|
19
|
-
# or set api_token on a Yo instance
|
25
|
+
# or set api_token on a Yo instance:
|
20
26
|
|
21
27
|
Hey::Yo.new(api_token: '3858f62230ac3c915f300c664312c63f').all
|
28
|
+
|
29
|
+
# or Yo a specific user:
|
30
|
+
|
31
|
+
Hey::Yo.user "WORLDCUP" # or...
|
32
|
+
Hey::Yo.new(api_token: '3858f62230ac3c915f300c664312c63f').user "WORLDCUP"
|
22
33
|
```
|
23
34
|
|
24
|
-
That's it!
|
35
|
+
That's it!
|
data/Rakefile
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
require 'rake'
|
2
2
|
require 'rake/testtask'
|
3
|
+
require 'rdoc/task'
|
4
|
+
|
5
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
6
|
+
rdoc.rdoc_dir = 'rdoc'
|
7
|
+
rdoc.title = 'Hey'
|
8
|
+
rdoc.options << '--line-numbers'
|
9
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
10
|
+
end
|
3
11
|
|
4
12
|
Rake::TestTask.new(:test) do |t|
|
5
13
|
t.libs = ["test", "lib"]
|
data/lib/hey.rb
CHANGED
data/lib/hey/version.rb
CHANGED
data/lib/hey/yo.rb
CHANGED
@@ -1,29 +1,72 @@
|
|
1
1
|
module Hey
|
2
|
+
# Sends requests to the Yo API endpoint.
|
2
3
|
class Yo
|
3
4
|
|
5
|
+
# (Optional) Should be set if an API token hasn't be set
|
6
|
+
# on the Hey module.
|
4
7
|
attr_accessor :api_token
|
5
8
|
|
9
|
+
# Optionally accepts a hash containing an API token.
|
10
|
+
# Defaults to the API token set on the Hey module.
|
11
|
+
#
|
12
|
+
# Hey::Yo.new api_token: '3858f62230ac3c915f300c664312c63f'
|
6
13
|
def initialize options = {}
|
7
14
|
@api_token = options[:api_token] || Hey.api_token
|
8
15
|
end
|
9
16
|
|
17
|
+
# Sends a request to the +yoall+ endpoint.
|
18
|
+
# Raises a +MissingAPITokenError+ error if an API token
|
19
|
+
# hasn't been set on the Hey module or Yo instance.
|
10
20
|
def all
|
11
21
|
raise MissingAPITokenError unless api_token
|
12
|
-
post_request
|
22
|
+
post_request 'yoall'
|
13
23
|
end
|
14
24
|
|
25
|
+
# Sends a request to a user using the +yo+ endpoint.
|
26
|
+
# Raises a +MissingAPITokenError+ error if an API token
|
27
|
+
# hasn't been set on the Hey module or Yo instance.
|
28
|
+
#
|
29
|
+
# Hey::Yo.new.user "worldcup"
|
30
|
+
def user name
|
31
|
+
raise MissingAPITokenError unless api_token
|
32
|
+
post_request 'yo', username: name
|
33
|
+
end
|
34
|
+
|
35
|
+
# Sends a request to the +yoall+ endpoint using the
|
36
|
+
# API token set on the Hey module.
|
15
37
|
def self.all
|
16
38
|
new.all
|
17
39
|
end
|
18
40
|
|
41
|
+
# Sends a request to a user using the +yo+ endpoint.
|
42
|
+
# Raises a +MissingAPITokenError+ error if an API token
|
43
|
+
# hasn't been set on the Hey module.
|
44
|
+
#
|
45
|
+
# Hey::Yo.user "worldcup"
|
46
|
+
def self.user name
|
47
|
+
new.user name
|
48
|
+
end
|
49
|
+
|
19
50
|
private
|
20
51
|
|
21
|
-
def post_request
|
52
|
+
def post_request method, params = {} #:nodoc:
|
53
|
+
params = params.merge api_token: api_token
|
22
54
|
uri = URI("http://api.justyo.co/#{method}/")
|
23
|
-
request = Net::HTTP.post_form uri,
|
24
|
-
|
55
|
+
request = Net::HTTP.post_form uri, params
|
56
|
+
raise_for_invalid_code! request
|
25
57
|
request
|
26
58
|
end
|
27
59
|
|
60
|
+
def raise_for_invalid_code! request #:nodoc:
|
61
|
+
response = JSON.parse(request.body)
|
62
|
+
return unless response["code"] && response["code"] == 141
|
63
|
+
case response["error"]
|
64
|
+
when "NO SUCH USER"
|
65
|
+
raise NoSuchUserError
|
66
|
+
else
|
67
|
+
raise InvalidAPITokenError
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
28
71
|
end
|
29
72
|
end
|
data/test/yo_test.rb
CHANGED
@@ -28,6 +28,16 @@ class YoTest < Minitest::Test
|
|
28
28
|
assert_sends_yo {Hey::Yo.all}
|
29
29
|
end
|
30
30
|
|
31
|
+
def test_user_sends_api_request
|
32
|
+
yo = Hey::Yo.new(api_token: 'foo')
|
33
|
+
assert_sends_yo {yo.user('YOJOBS')}
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_class_method_user_sends_api_request
|
37
|
+
Hey.api_token = 'foo'
|
38
|
+
assert_sends_yo {Hey::Yo.user('YOJOBS')}
|
39
|
+
end
|
40
|
+
|
31
41
|
def test_raises_no_api_token_error
|
32
42
|
Hey.api_token = nil
|
33
43
|
yo = Hey::Yo.new
|
@@ -37,10 +47,13 @@ class YoTest < Minitest::Test
|
|
37
47
|
end
|
38
48
|
|
39
49
|
def assert_sends_yo(&block)
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
50
|
+
mock_response = Net::HTTPResponse.new('1.1', '201', 'CREATED')
|
51
|
+
mock_response.stub(:read_body, "{\"code\": 201}") do
|
52
|
+
mock = MiniTest::Mock.new
|
53
|
+
mock.expect(:post_form, mock_response, [URI, Hash])
|
54
|
+
Net.stub_const(:HTTP, mock, &block)
|
55
|
+
assert mock.verify
|
56
|
+
end
|
44
57
|
end
|
45
58
|
|
46
59
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jack Jennings
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rdoc
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.1'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '4.1'
|
55
69
|
description: Sends a yo to your yo followers
|
56
70
|
email: j@ckjennin.gs
|
57
71
|
executables: []
|