dfg59-diggr 0.0.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +18 -0
- data/Rakefile +1 -1
- data/lib/diggr.rb +1 -1
- data/lib/diggr/json_parser.rb +3 -3
- data/lib/diggr/request.rb +9 -5
- data/lib/diggr/response_classes/story.rb +4 -10
- data/lib/diggr/response_classes/user.rb +1 -1
- data/test/test_request.rb +11 -0
- metadata +7 -8
- data/.DS_Store +0 -0
- data/README.txt +0 -113
data/History.txt
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
=== 0.1.3 / 2008-09-09
|
2
|
+
|
3
|
+
* 1 minor bug-fix
|
4
|
+
|
5
|
+
* Added more attributes to user class
|
6
|
+
|
7
|
+
=== 0.1.2 / 2008-09-09
|
8
|
+
|
9
|
+
* 1 minor bug-fix
|
10
|
+
|
11
|
+
* Singular responses work with Enumerable methods
|
12
|
+
|
13
|
+
=== 0.1.1 / 2008-09-08
|
14
|
+
|
15
|
+
* 1 major bug-fix
|
16
|
+
|
17
|
+
* Updated to work with activesupport 2.1.1
|
18
|
+
|
1
19
|
=== 0.1.0 / 2008-08-26
|
2
20
|
|
3
21
|
* 1 major enhancement
|
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ Hoe.new('diggr', Diggr::VERSION) do |p|
|
|
9
9
|
p.developer('Drew Olson', 'drew@drewolson.org')
|
10
10
|
p.extra_deps << ['need', '>= 1.0.2']
|
11
11
|
p.extra_deps << ['json', '>= 1.1.3']
|
12
|
-
p.extra_deps << ['activesupport', '>= 2.1.
|
12
|
+
p.extra_deps << ['activesupport', '>= 2.1.1']
|
13
13
|
p.remote_rdoc_dir = ''
|
14
14
|
end
|
15
15
|
|
data/lib/diggr.rb
CHANGED
data/lib/diggr/json_parser.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require 'active_support
|
2
|
+
require 'active_support'
|
3
3
|
require 'json'
|
4
4
|
require 'need'
|
5
5
|
need { 'api_error' }
|
@@ -42,9 +42,9 @@ module Diggr
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def find_class(collection_type)
|
45
|
-
file_name =
|
45
|
+
file_name = collection_type.singularize
|
46
46
|
need { File.join('response_classes',file_name) }
|
47
|
-
|
47
|
+
('Diggr::' + file_name.camelize).constantize
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
data/lib/diggr/request.rb
CHANGED
@@ -12,7 +12,7 @@ module Diggr
|
|
12
12
|
|
13
13
|
def initialize
|
14
14
|
@end_point = ''
|
15
|
-
@options =
|
15
|
+
@options = ''
|
16
16
|
end
|
17
17
|
|
18
18
|
def options(params)
|
@@ -31,7 +31,13 @@ module Diggr
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def each(&block)
|
34
|
-
fetch
|
34
|
+
result = fetch
|
35
|
+
|
36
|
+
if result.kind_of? Array
|
37
|
+
fetch.each(&block)
|
38
|
+
else
|
39
|
+
yield result
|
40
|
+
end
|
35
41
|
end
|
36
42
|
|
37
43
|
def fetch
|
@@ -59,9 +65,7 @@ module Diggr
|
|
59
65
|
end
|
60
66
|
|
61
67
|
def path
|
62
|
-
|
63
|
-
path += @options if @options
|
64
|
-
path
|
68
|
+
@end_point + "?appkey=#{cleanse(Diggr::Constants::APP_KEY)}" + @options
|
65
69
|
end
|
66
70
|
end
|
67
71
|
end
|
@@ -12,21 +12,15 @@ module Diggr
|
|
12
12
|
|
13
13
|
def self.new_from_parsed_json(data)
|
14
14
|
story = Story.new
|
15
|
+
|
16
|
+
%w(id link submit_date diggs comments title description status media href).each do |attribute|
|
17
|
+
story.send("#{attribute}=",data[attribute]) if data[attribute]
|
18
|
+
end
|
15
19
|
|
16
|
-
story.id = data['id'] if data['id']
|
17
|
-
story.link = data['link'] if data['link']
|
18
|
-
story.submit_date = data['submit_date'] if data['submit_date']
|
19
|
-
story.diggs = data['diggs'] if data['diggs']
|
20
|
-
story.comments = data['comments'] if data['comments']
|
21
|
-
story.title = data['title'] if data['title']
|
22
|
-
story.description = data['description'] if data['description']
|
23
|
-
story.status = data['status'] if data['status']
|
24
|
-
story.media = data['media'] if data['media']
|
25
20
|
story.user = Diggr::User.new_from_parsed_json(data['user']) if data['user']
|
26
21
|
story.topic = Diggr::Topic.new_from_parsed_json(data['topic']) if data['topic']
|
27
22
|
story.container = Diggr::Container.new_from_parsed_json(data['container']) if data['container']
|
28
23
|
story.thumbnail = Diggr::Photo.new_from_parsed_json(data['thumbnail']) if data['thumbnail']
|
29
|
-
story.href = data['href'] if data['href']
|
30
24
|
|
31
25
|
story
|
32
26
|
end
|
data/test/test_request.rb
CHANGED
@@ -108,4 +108,15 @@ class TestRequest < Test::Unit::TestCase
|
|
108
108
|
assert_instance_of Diggr::Story, item
|
109
109
|
end
|
110
110
|
end
|
111
|
+
|
112
|
+
def test_each_with_singular_response
|
113
|
+
story = Diggr::Story.new
|
114
|
+
Diggr::JSONParser.any_instance.stubs(:parse).with(story).returns(story)
|
115
|
+
request = Diggr::Request.new
|
116
|
+
request.stubs(:make_request).returns(story)
|
117
|
+
|
118
|
+
request.each do |item|
|
119
|
+
assert_instance_of Diggr::Story, item
|
120
|
+
end
|
121
|
+
end
|
111
122
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dfg59-diggr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Drew Olson
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-11-15 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -37,7 +37,7 @@ dependencies:
|
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 2.1.
|
40
|
+
version: 2.1.1
|
41
41
|
version:
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: hoe
|
@@ -46,9 +46,9 @@ dependencies:
|
|
46
46
|
requirements:
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: 1.
|
49
|
+
version: 1.8.2
|
50
50
|
version:
|
51
|
-
description:
|
51
|
+
description:
|
52
52
|
email:
|
53
53
|
- drew@drewolson.org
|
54
54
|
executables: []
|
@@ -60,7 +60,6 @@ extra_rdoc_files:
|
|
60
60
|
- Manifest.txt
|
61
61
|
- README.txt
|
62
62
|
files:
|
63
|
-
- .DS_Store
|
64
63
|
- History.txt
|
65
64
|
- Manifest.txt
|
66
65
|
- README.txt
|
@@ -93,7 +92,7 @@ files:
|
|
93
92
|
- test/test_topic.rb
|
94
93
|
- test/test_user.rb
|
95
94
|
has_rdoc: true
|
96
|
-
homepage:
|
95
|
+
homepage:
|
97
96
|
post_install_message:
|
98
97
|
rdoc_options:
|
99
98
|
- --main
|
@@ -118,7 +117,7 @@ rubyforge_project: diggr
|
|
118
117
|
rubygems_version: 1.2.0
|
119
118
|
signing_key:
|
120
119
|
specification_version: 2
|
121
|
-
summary:
|
120
|
+
summary: ruby wrapper for digg api
|
122
121
|
test_files:
|
123
122
|
- test/test_api.rb
|
124
123
|
- test/test_comment.rb
|
data/.DS_Store
DELETED
Binary file
|
data/README.txt
DELETED
@@ -1,113 +0,0 @@
|
|
1
|
-
= diggr
|
2
|
-
|
3
|
-
* http://diggr.rubyforge.org
|
4
|
-
|
5
|
-
== DESCRIPTION:
|
6
|
-
|
7
|
-
Diggr is a ruby wrapper for the Digg API.
|
8
|
-
|
9
|
-
Diggr strives to remain consistent with the Digg API endpoints listed here:
|
10
|
-
http://apidoc.digg.com/CompleteList. Endpoints are created in Diggr with method calls.
|
11
|
-
Each node in an endpoint becomes a method call and each node which is an argument becomes
|
12
|
-
an argument to the previous method. As an example, the following endpoint
|
13
|
-
|
14
|
-
/user/{user name}
|
15
|
-
|
16
|
-
in which the user name is "johndoe" would be created with this Diggr call:
|
17
|
-
|
18
|
-
diggr.user("johndoe")
|
19
|
-
|
20
|
-
To send the request to the Digg API and retrieve the results of the call, Diggr requests are
|
21
|
-
terminated in one of two ways.
|
22
|
-
|
23
|
-
1. Using the fetch method. By ending your request with the fetch method, your result will be
|
24
|
-
returned to you. If the request is singular, you will receive a single object as a
|
25
|
-
response. If the request is plural, you will receive a collection of objects stored in an
|
26
|
-
array.
|
27
|
-
|
28
|
-
2. Using any Enumerable method. This works only on plural requests. In this case, it is
|
29
|
-
unnecessary to use the fetch method.
|
30
|
-
|
31
|
-
See the synopsis for examples of each of these types of calls.
|
32
|
-
|
33
|
-
Options such as count or offset can be set using the options method and providing a hash of
|
34
|
-
arguments. See synopsis for more information.
|
35
|
-
|
36
|
-
Note: In an effort to remain consistent with the Digg API, some method names do not follow
|
37
|
-
the ruby idiom of underscores. Although somewhat ugly, this allows a user read the Digg API
|
38
|
-
and understand the exact methods to call in Diggr to achieve their desired results.
|
39
|
-
|
40
|
-
== FEATURES/PROBLEMS:
|
41
|
-
|
42
|
-
* Diggr wraps the Digg API and returns both single elements and collections based on the request
|
43
|
-
|
44
|
-
== SYNOPSIS:
|
45
|
-
|
46
|
-
require 'rubygems'
|
47
|
-
require 'diggr'
|
48
|
-
|
49
|
-
diggr = Diggr::API.new
|
50
|
-
|
51
|
-
# retrieve a single user by user name and print the number of profile views
|
52
|
-
user = diggr.user("johndoe").fetch
|
53
|
-
puts user.profileviews
|
54
|
-
|
55
|
-
# iterator over the most recent 10 stories (default return size) and print their titles
|
56
|
-
diggr.stories.each do |story|
|
57
|
-
puts story.title
|
58
|
-
end
|
59
|
-
|
60
|
-
# print the title of the 3 most recent hot stories
|
61
|
-
diggr.stories.hot.options(:count => 3).each do |story|
|
62
|
-
puts story.title
|
63
|
-
end
|
64
|
-
|
65
|
-
# build an array of stories whos title contains "foo"
|
66
|
-
diggr.stories.inject([]) do |array,story|
|
67
|
-
array << story if story.title =~ /foo/
|
68
|
-
array
|
69
|
-
end
|
70
|
-
|
71
|
-
# print the title of the 2nd and 3rd most recent stories
|
72
|
-
diggr.stories.options(:count => 2, :offset => 2).each do |story|
|
73
|
-
puts story.title
|
74
|
-
end
|
75
|
-
|
76
|
-
== REQUIREMENTS:
|
77
|
-
|
78
|
-
* need 1.0.2 or greater
|
79
|
-
* json 1.1.3 or greater
|
80
|
-
* activesupport 2.1.0 or greater
|
81
|
-
|
82
|
-
== INSTALL:
|
83
|
-
|
84
|
-
* install from rubyforge (major releases)
|
85
|
-
* sudo gem install diggr
|
86
|
-
|
87
|
-
* install from github (major and minor releases)
|
88
|
-
* sudo gem install dfg59-diggr --source=http://gems.github.com
|
89
|
-
|
90
|
-
== LICENSE:
|
91
|
-
|
92
|
-
(The MIT License)
|
93
|
-
|
94
|
-
Copyright (c) 2008 FIX
|
95
|
-
|
96
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
97
|
-
a copy of this software and associated documentation files (the
|
98
|
-
'Software'), to deal in the Software without restriction, including
|
99
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
100
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
101
|
-
permit persons to whom the Software is furnished to do so, subject to
|
102
|
-
the following conditions:
|
103
|
-
|
104
|
-
The above copyright notice and this permission notice shall be
|
105
|
-
included in all copies or substantial portions of the Software.
|
106
|
-
|
107
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
108
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
109
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
110
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
111
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
112
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
113
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|