flattr 0.2.2 → 0.2.3
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.
- data/README.md +13 -2
- data/lib/flattr/client.rb +1 -0
- data/lib/flattr/client/categories.rb +20 -0
- data/lib/flattr/client/languages.rb +9 -0
- data/lib/flattr/client/things.rb +118 -7
- data/lib/flattr/client/users.rb +50 -0
- data/lib/flattr/search.rb +20 -0
- data/lib/flattr/version.rb +1 -1
- metadata +20 -18
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
# Flattr API wrapper
|
1
|
+
# Flattr API wrapper
|
2
2
|
|
3
|
-
This gem is a wrapper around the Flattr API. With the gem you can search things, add new thing and much more.
|
3
|
+
This gem is a wrapper around the Flattr API. With the gem you can search things, add new thing and much more. If you want information about updates follow [@simongate](http://twitter.com/simongate) on twitter.
|
4
|
+
|
5
|
+
[](https://flattr.com/submit/auto?user_id=smgt&url=https://github.com/simon/flattr&title=Flattr API gem&language=en_GB&tags=github&category=software)
|
4
6
|
|
5
7
|
## Build status
|
6
8
|
|
@@ -22,6 +24,15 @@ Installation is easy, just install the gem with.
|
|
22
24
|
|
23
25
|
To talk with all of Flattr API resources you need to [register a application](http://flattr.com/apps). This will give you a *client id* and a *client secret* whom you can exchange for a *access token*. The *access token* is then used to access the resources in the Flattr API that needs authentication. You can find more information about the API in [Flattr developer documents](http://developers.flattr.net/v2).
|
24
26
|
|
27
|
+
### Resources
|
28
|
+
|
29
|
+
You can find documentation about available resources in the code.
|
30
|
+
|
31
|
+
* [things](https://github.com/simon/flattr/blob/master/lib/flattr/client/things.rb)
|
32
|
+
* [users](https://github.com/simon/flattr/blob/master/lib/flattr/client/users.rb)
|
33
|
+
* [categories](https://github.com/simon/flattr/blob/master/lib/flattr/client/categories.rb)
|
34
|
+
* [languages](https://github.com/simon/flattr/blob/master/lib/flattr/client/languages.rb)
|
35
|
+
|
25
36
|
### Access public resources
|
26
37
|
|
27
38
|
There are several public available resources in the Flattr API where you don't need to authenticate to access.
|
data/lib/flattr/client.rb
CHANGED
@@ -4,12 +4,32 @@ module Flattr
|
|
4
4
|
class Client
|
5
5
|
module Categories
|
6
6
|
|
7
|
+
# Public: Get a list of available categories
|
8
|
+
#
|
9
|
+
# Examples
|
10
|
+
#
|
11
|
+
# f = Flattr.new
|
12
|
+
# f.categories
|
13
|
+
# # => [Flattr::Category]
|
14
|
+
#
|
15
|
+
# Returns a Array with Flattr::Category inside
|
7
16
|
def categories
|
8
17
|
@categories ||= get('/rest/v2/categories').map do |category|
|
9
18
|
Flattr::Category.new(category)
|
10
19
|
end
|
11
20
|
end
|
12
21
|
|
22
|
+
# Public: Get a category by id
|
23
|
+
#
|
24
|
+
# id - id of the catgory
|
25
|
+
#
|
26
|
+
# Examples
|
27
|
+
#
|
28
|
+
# f = Flattr.new
|
29
|
+
# f.category("software")
|
30
|
+
# # => Flattr::Category
|
31
|
+
#
|
32
|
+
# Returns a Flattr::Category on success and nil on failure
|
13
33
|
def category(id)
|
14
34
|
categories.select do |category|
|
15
35
|
category.id == id
|
@@ -4,6 +4,15 @@ module Flattr
|
|
4
4
|
class Client
|
5
5
|
module Languages
|
6
6
|
|
7
|
+
# Public: Returns available languages on flattr
|
8
|
+
#
|
9
|
+
# Examples
|
10
|
+
#
|
11
|
+
# f = Flattr.new
|
12
|
+
# f.languages
|
13
|
+
# # => [Flattr::Language]
|
14
|
+
#
|
15
|
+
# Returns a Array with Flattr::Language inside
|
7
16
|
def languages
|
8
17
|
get("/rest/v2/languages").map do |language|
|
9
18
|
Flattr::Language.new(language)
|
data/lib/flattr/client/things.rb
CHANGED
@@ -4,36 +4,147 @@ module Flattr
|
|
4
4
|
class Client
|
5
5
|
module Things
|
6
6
|
|
7
|
+
# Public: Fetch a thing
|
8
|
+
#
|
9
|
+
# id - id of the thing you would like to fetch
|
10
|
+
#
|
11
|
+
# Examples
|
12
|
+
#
|
13
|
+
# f = Flattr.new
|
14
|
+
# f.thing(450287)
|
15
|
+
# #=> Flattr::Thing
|
16
|
+
#
|
17
|
+
# Returns the thing
|
18
|
+
# Raises error on failure
|
7
19
|
def thing(id)
|
8
20
|
thing = get("/rest/v2/things/#{id}")
|
9
21
|
Flattr::Thing.new(thing)
|
10
22
|
end
|
11
23
|
|
24
|
+
# Public: Create a thing
|
25
|
+
#
|
26
|
+
# url - URL you want to submit
|
27
|
+
# opts - A Hash containing the thing attribtues (default: {})
|
28
|
+
# :title - title of the thing (optional).
|
29
|
+
# :description - description of the thing (optional).
|
30
|
+
# :category - category of the thing (optional).
|
31
|
+
# :language - language of the thing (optional).
|
32
|
+
# :tags - tags of the thing (optional).
|
33
|
+
# :hidden - boolean toggling if thing should be hidden or not (optional).
|
34
|
+
#
|
35
|
+
# Returns new thing
|
36
|
+
# Raises error on failure
|
12
37
|
def thing_new(url, opts = {})
|
13
38
|
response = post("/rest/v2/things", opts.merge(:url => url))
|
14
39
|
thing = get("/rest/v2/things/#{response[:id]}")
|
15
40
|
Flattr::Thing.new(thing)
|
16
41
|
end
|
17
42
|
|
43
|
+
# Public: Update a thing
|
44
|
+
#
|
45
|
+
# id - id of the thing to update
|
46
|
+
# opts - a Hash containing the attributes to update (default: {})
|
47
|
+
# :title - title of the thing (optional).
|
48
|
+
# :description - description of the thing (optional).
|
49
|
+
# :category - category of the thing (optional).
|
50
|
+
# :language - language of the thing (optional).
|
51
|
+
# :tags - tags of the thing (optional).
|
52
|
+
# :hidden - boolean toggling if thing should be hidden or not (optional).
|
53
|
+
#
|
54
|
+
# Returns updated thing
|
55
|
+
# Raises Error on failure
|
18
56
|
def thing_update(id, opts = {})
|
19
57
|
patch("/rest/v2/things/#{id}", opts)
|
20
58
|
thing = get("/rest/v2/things/#{id}")
|
21
59
|
Flattr::Thing.new(thing)
|
22
60
|
end
|
23
61
|
|
62
|
+
# Public: Delete a thing
|
63
|
+
#
|
64
|
+
# id - id of the thing you want to delete
|
65
|
+
#
|
66
|
+
# Example
|
67
|
+
#
|
68
|
+
# f = Flattr.new
|
69
|
+
# f.thing_delete(1)
|
70
|
+
# # => true
|
71
|
+
#
|
72
|
+
# Returns true if successful
|
73
|
+
# Raises Error on failure
|
24
74
|
def thing_delete(id)
|
25
75
|
thing = delete("/rest/v2/things/#{id}")
|
26
|
-
|
76
|
+
if thing.nil? || thing == ""
|
77
|
+
return true
|
78
|
+
else
|
79
|
+
return false
|
80
|
+
end
|
27
81
|
end
|
28
82
|
|
29
|
-
|
30
|
-
|
31
|
-
|
83
|
+
# Public: Flattr a thing
|
84
|
+
#
|
85
|
+
# id - id of the thing you want to flattr
|
86
|
+
#
|
87
|
+
# Example
|
88
|
+
#
|
89
|
+
# f = Flattr.new
|
90
|
+
# f.thing_flattr(1)
|
91
|
+
# # => true
|
92
|
+
#
|
93
|
+
# Returns true
|
94
|
+
def thing_flattr(id)
|
95
|
+
post("/rest/v2/things/#{id}/flattr")
|
32
96
|
end
|
33
97
|
|
34
|
-
|
35
|
-
|
36
|
-
|
98
|
+
# Public: Search things
|
99
|
+
#
|
100
|
+
# params - The Hash options used to configure search (default: {})
|
101
|
+
# :query - A free text search query (optional).
|
102
|
+
# :language - Filter by language (optional).
|
103
|
+
# :category - Filter by category (optional).
|
104
|
+
# :user - Search only a users things (optional).
|
105
|
+
# :tags - Filter by tags (optional).
|
106
|
+
# :page - Show page (optional).
|
107
|
+
# :count - How many items per page (optional).
|
108
|
+
#
|
109
|
+
# Examples
|
110
|
+
#
|
111
|
+
# # Return a search result containgin 'smgt'
|
112
|
+
# f = Flattr.new
|
113
|
+
# f.things_search(:query => "smgt")
|
114
|
+
#
|
115
|
+
# # Return a search result containing 'ruby' from user 'smgt'
|
116
|
+
# f = Flattr.new
|
117
|
+
# f.things_search(:query => "ruby", :user => 'smgt')
|
118
|
+
#
|
119
|
+
# Returns Flattr::Search
|
120
|
+
def thing_search(params = {})
|
121
|
+
result = get("/rest/v2/things/search", params)
|
122
|
+
Flattr::Search.new(result)
|
123
|
+
end
|
124
|
+
|
125
|
+
# Public: Check if a URL is registred as a thing
|
126
|
+
#
|
127
|
+
# url - URL to lookup
|
128
|
+
#
|
129
|
+
# Examples
|
130
|
+
#
|
131
|
+
# f = Flattr.new
|
132
|
+
# f.things_lookup("http://flattr.com")
|
133
|
+
# # => nil
|
134
|
+
#
|
135
|
+
# f = Flattr.new
|
136
|
+
# f.things_lookup("http://github.com/simon/flattr")
|
137
|
+
# # => Flattr::Thing
|
138
|
+
#
|
139
|
+
# Returns Flattr::Thing on success and nil on failure
|
140
|
+
def thing_lookup(url)
|
141
|
+
lookup = get("/rest/v2/things/lookup", {:url => url})
|
142
|
+
if lookup["location"]
|
143
|
+
thing = get(lookup['location'])
|
144
|
+
Flattr::Thing.new(thing)
|
145
|
+
else
|
146
|
+
nil
|
147
|
+
end
|
37
148
|
end
|
38
149
|
|
39
150
|
end
|
data/lib/flattr/client/users.rb
CHANGED
@@ -4,12 +4,62 @@ module Flattr
|
|
4
4
|
class Client
|
5
5
|
module Users
|
6
6
|
|
7
|
+
# Public: Get a user or the one currently authenticated
|
8
|
+
#
|
9
|
+
# username - username of the user you want to get (optional)
|
10
|
+
#
|
11
|
+
# Examples
|
12
|
+
#
|
13
|
+
# f = Flattr.new
|
14
|
+
# f.user("smgt")
|
15
|
+
# # => #<Flattr::User...
|
16
|
+
#
|
17
|
+
# Returns a Flattr::User if successful
|
18
|
+
# Raises a ERROR on failure
|
7
19
|
def user(username=nil)
|
8
20
|
user = username || self.current_user.username
|
9
21
|
user = get("/rest/v2/users/#{user}")
|
10
22
|
Flattr::User.new(user)
|
11
23
|
end
|
12
24
|
|
25
|
+
# Public: Get a users things
|
26
|
+
#
|
27
|
+
# username - username of the user you want to get (optional)
|
28
|
+
#
|
29
|
+
# Examples
|
30
|
+
#
|
31
|
+
# f = Flattr.new
|
32
|
+
# f.user_things("smgt")
|
33
|
+
# # => [#<Flattr::Thing...
|
34
|
+
#
|
35
|
+
# Returns a Array with Flattr::User's inside if successful
|
36
|
+
# Raises a ERROR on failure
|
37
|
+
def user_things(username=nil, args={})
|
38
|
+
user = username || self.current_user.username
|
39
|
+
get("/rest/v2/users/#{user}/things", args).map do |thing|
|
40
|
+
Flattr::Thing.new(thing)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Public: Get a users flattrs
|
45
|
+
#
|
46
|
+
# username - username of the user you want to get (optional)
|
47
|
+
#
|
48
|
+
# Examples
|
49
|
+
#
|
50
|
+
# f = Flattr.new
|
51
|
+
# f.user_flattrs("smgt")
|
52
|
+
# # => [{"type" => "flattr"....
|
53
|
+
#
|
54
|
+
# Returns a Array with flattrs if successful
|
55
|
+
# Raises a ERROR on failure
|
56
|
+
def user_flattrs(username=nil, args={})
|
57
|
+
user = username || self.current_user.username
|
58
|
+
get("/rest/v2/users/#{user}/flattrs").map do |flattr|
|
59
|
+
flattr
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
13
63
|
end
|
14
64
|
end
|
15
65
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'flattr/base'
|
2
|
+
|
3
|
+
module Flattr
|
4
|
+
class Search < Flattr::Base
|
5
|
+
|
6
|
+
lazy_attr_reader :total_items, :items, :page, :things
|
7
|
+
|
8
|
+
def initialize(attrs={})
|
9
|
+
if attrs["items"] > 0
|
10
|
+
items = []
|
11
|
+
attrs["things"].each do |item|
|
12
|
+
items << Flattr::Thing.new(item)
|
13
|
+
end
|
14
|
+
attrs["things"] = items
|
15
|
+
end
|
16
|
+
super attrs
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
data/lib/flattr/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flattr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2012-01-16 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: faraday
|
17
|
-
requirement: &
|
17
|
+
requirement: &70335945795100 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70335945795100
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: multi_json
|
28
|
-
requirement: &
|
28
|
+
requirement: &70335945794620 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70335945794620
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: json
|
39
|
-
requirement: &
|
39
|
+
requirement: &70335945794040 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70335945794040
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: rake
|
50
|
-
requirement: &
|
50
|
+
requirement: &70335945793560 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70335945793560
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: rdiscount
|
61
|
-
requirement: &
|
61
|
+
requirement: &70335945793020 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ! '>='
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: '0'
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *70335945793020
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: rspec
|
72
|
-
requirement: &
|
72
|
+
requirement: &70335945792400 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ! '>='
|
@@ -77,10 +77,10 @@ dependencies:
|
|
77
77
|
version: '0'
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *70335945792400
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: simplecov
|
83
|
-
requirement: &
|
83
|
+
requirement: &70335945791660 !ruby/object:Gem::Requirement
|
84
84
|
none: false
|
85
85
|
requirements:
|
86
86
|
- - ! '>='
|
@@ -88,10 +88,10 @@ dependencies:
|
|
88
88
|
version: '0'
|
89
89
|
type: :development
|
90
90
|
prerelease: false
|
91
|
-
version_requirements: *
|
91
|
+
version_requirements: *70335945791660
|
92
92
|
- !ruby/object:Gem::Dependency
|
93
93
|
name: webmock
|
94
|
-
requirement: &
|
94
|
+
requirement: &70335945790720 !ruby/object:Gem::Requirement
|
95
95
|
none: false
|
96
96
|
requirements:
|
97
97
|
- - ! '>='
|
@@ -99,7 +99,7 @@ dependencies:
|
|
99
99
|
version: '0'
|
100
100
|
type: :development
|
101
101
|
prerelease: false
|
102
|
-
version_requirements: *
|
102
|
+
version_requirements: *70335945790720
|
103
103
|
description:
|
104
104
|
email:
|
105
105
|
- simon@smgt.me
|
@@ -142,6 +142,7 @@ files:
|
|
142
142
|
- lib/flattr/request.rb
|
143
143
|
- lib/flattr/request/oauth2.rb
|
144
144
|
- lib/flattr/response/parse_json.rb
|
145
|
+
- lib/flattr/search.rb
|
145
146
|
- lib/flattr/thing.rb
|
146
147
|
- lib/flattr/user.rb
|
147
148
|
- lib/flattr/version.rb
|
@@ -174,3 +175,4 @@ summary: Flattr API wrapper
|
|
174
175
|
test_files:
|
175
176
|
- spec/flattr_spec.rb
|
176
177
|
- spec/helper.rb
|
178
|
+
has_rdoc:
|