flattr 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ coverage/*
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - jruby
6
+ - rbx
7
+ - ree
data/README.md CHANGED
@@ -1,14 +1,97 @@
1
- # Flattr
1
+ # Flattr API wrapper gem
2
2
 
3
- This gem is a wrapper around version 2 of the [Flattr](http://flattr.com) [REST
4
- API](http://developers.flattr.com/v2).
3
+ This gem is a wrapper around the Flattr API. With the gem you can search things, add new thing and much more.
5
4
 
6
5
  ## Build status
7
6
 
8
7
  [![Build
9
8
  Status](https://secure.travis-ci.org/simon/flattr.png)](http://travis-ci.org/simon/flattr)
10
9
 
11
- ## Examples
10
+ ## Installation
11
+
12
+ Installation is easy, just install the gem with.
13
+
14
+ `gem install flattr`
15
+
16
+ ### Dependencies
17
+
18
+ * Faraday
19
+ * multi_json
20
+
21
+ ## Usage
22
+
23
+ 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
+
25
+ ### Access public resources
26
+
27
+ There are several public available resources in the Flattr API where you don't need to authenticate to access.
28
+
29
+ ```ruby
30
+ # Fetch a public thing
31
+ flattr = Flattr.new
32
+
33
+ flattr.thing 423405
34
+ # => #<Flattr::Thing:0x007fccbb4f1d40 @attrs={"type"=>"thing", "resource"=>"https://api.flattr.com/rest/v2/things/423405", "link"=>"https://flattr.com/thing/423405", "id"=>423405, "url"=>"http://blog.flattr.net/2011/10/api-v2-beta-out-whats-changed/", "language"=>"en_GB", "category"=>"text", "owner"=>{"type"=>"user", "resource"=>"https://api.flattr.com/rest/v2/users/flattr", "link"=>"https://flattr.com/profile/flattr", "username"=>"flattr"}, "hidden"=>false, "created_at"=>1319704532, "tags"=>["api"], "flattrs"=>9, "description"=>"We have been working hard to deliver a great experience for developers and tried to build a good foundation for easily add new features. The API will remain in beta for a while for us to kill quirks and refine some of the resources, this means there might be big changes without notice for ...", "title"=>"API v2 beta out – what’s changed?"}>
35
+ ```
36
+
37
+ ### Access protected resources
38
+
39
+ The gem allows makes it easy to do the oauth2 dance.
40
+
41
+ ```ruby
42
+ Flattr.configure do |config|
43
+ config.client_id = '1234'
44
+ config.client_secret = '4567'
45
+ end
46
+
47
+ flattr = Flattr.new
48
+
49
+ puts 'Open this URL in your browser to authenticate your application'
50
+ puts flattr.authorize_url
51
+
52
+ puts "\n\n"
53
+
54
+ puts 'When your with the authentication the browser will redirect you to the callback URL you specified when creating a application. It has also included a code in the query string. Copy paste this code to the command line.'
55
+ print 'code: '
56
+ code = gets
57
+
58
+ # Use the code and exchange it for a access_token
59
+ flattr.get_access_token code
60
+
61
+ # You are now authorized! ;)
62
+
63
+ ```
64
+
65
+ ### Scopes available
66
+
67
+ If you request a access token without any scopes you won't be able to flattr other users things and such. The scopes available are:
68
+
69
+ * `thing` - Create and update things
70
+ * `flattr` - Flattr things
71
+ * `extendedread` - Access all the information about users
72
+
73
+ ## What needs to be done
74
+
75
+ * Add error reporting
76
+ * More tests are needed, coverage isn't that good
77
+ * Add all the Flattr API resources
78
+
79
+ ## Supported Ruby Versions
80
+
81
+ This library aims to support and is [tested against](http://travis-ci.org/simon/flattr) the following Ruby implementations:
82
+
83
+ * Ruby 1.8.7
84
+ * Ruby 1.9.2
85
+ * Ruby 1.9.3
86
+ * JRuby
87
+ * Rubinius
88
+ * Ruby Enterprise Edition
89
+
90
+ If something doesn't work on one of these interpreters, it should be considered a bug.
91
+
92
+ This library may inadvertently work (or seem to work) on other Ruby implementations, however support will only be provided for the versions listed above.
93
+
94
+ If you would like this library to support another Ruby version, you may volunteer to be a maintainer. Being a maintainer entails making sure all tests run and pass on that implementation. When something breaks on your implementation, you will be personally responsible for providing patches in a timely fashion. If critical issues for a particular implementation exist at the time of a major release, support for that Ruby version may be dropped.
12
95
 
13
96
  ## Copyright
14
97
 
data/Rakefile CHANGED
@@ -1 +1,10 @@
1
- require "bundler/gem_tasks"
1
+ #!/usr/bin/env rake
2
+
3
+ require 'bundler'
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task :test => :spec
10
+ task :default => :spec
data/flattr.gemspec CHANGED
@@ -7,9 +7,8 @@ Gem::Specification.new do |s|
7
7
  s.version = Flattr::Version.to_s
8
8
  s.authors = ["Simon Gate", "Joel Hansson"]
9
9
  s.email = ["simon@smgt.me", "joel.hansson@gmail.com"]
10
- s.homepage = ""
11
- s.summary = %q{Write a gem summary}
12
- s.description = %q{Write a gem description}
10
+ s.homepage = "http://github.com/simon/flattr"
11
+ s.summary = %q{Flattr API wrapper}
13
12
 
14
13
  s.rubyforge_project = "flattr"
15
14
 
@@ -21,7 +20,10 @@ Gem::Specification.new do |s|
21
20
  s.add_dependency 'faraday'
22
21
  s.add_dependency 'multi_json'
23
22
 
24
- # specify any dependencies here; for example:
25
- # s.add_development_dependency "rspec"
26
- # s.add_runtime_dependency "rest-client"
23
+ s.add_development_dependency 'json'
24
+ s.add_development_dependency 'rake'
25
+ s.add_development_dependency 'rdiscount'
26
+ s.add_development_dependency 'rspec'
27
+ s.add_development_dependency 'simplecov'
28
+ s.add_development_dependency 'webmock'
27
29
  end
data/lib/flattr/client.rb CHANGED
@@ -47,5 +47,10 @@ module Flattr
47
47
  @current_user ||= Flattr::User.new(self.verify_credentials)
48
48
  end
49
49
 
50
+ def base64_encode str
51
+ [str].pack("m9999").chomp
52
+ end
53
+
54
+
50
55
  end
51
56
  end
@@ -6,7 +6,7 @@ require 'flattr/request/oauth2'
6
6
  module Flattr
7
7
  module Connection
8
8
  private
9
- def connection(options={})
9
+ def connection(connection_options={})
10
10
  default_options = {
11
11
  :headers => {
12
12
  :accept => 'application/json',
@@ -14,14 +14,14 @@ module Flattr
14
14
  },
15
15
  :proxy => proxy,
16
16
  :ssl => {:verify => false},
17
- :url => options.fetch(:endpoint, endpoint),
17
+ :url => endpoint,
18
18
  }
19
19
  Faraday.new(default_options.deep_merge(connection_options)) do |builder|
20
20
  #builder.use Faraday::Request::Multipart
21
21
  builder.use Faraday::Request::JSON
22
22
  builder.use Faraday::Request::UrlEncoded
23
23
  builder.use Flattr::Request::FlattrOAuth2, credentials if credentials?
24
- builder.use Flattr::Response::ParseJson unless options[:raw]
24
+ builder.use Flattr::Response::ParseJson unless connection_options[:raw]
25
25
  builder.adapter(adapter)
26
26
  end
27
27
  end
data/lib/flattr/oauth2.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Flattr
2
2
  module OAuth2
3
3
 
4
- def authorize_path(opts = {})
4
+ def authorize_url(opts = {})
5
5
 
6
6
  default_options = {
7
7
  :client_id => client_id,
@@ -25,7 +25,16 @@ module Flattr
25
25
  end
26
26
 
27
27
  def get_access_token(code)
28
- post(token_endpoint, {:code => code, :grant_type => 'authorization_code'}, options)
28
+ response = post(token_endpoint, {
29
+ :code => code,
30
+ :grant_type => 'authorization_code'
31
+ },{
32
+ :headers => {
33
+ :authorization => "Basic #{base64_encode("#{client_id}:#{client_secret}")}"
34
+ }}
35
+ )
36
+ self.access_token = response['access_token']
37
+ access_token
29
38
  end
30
39
 
31
40
  end
@@ -23,10 +23,6 @@ module Flattr
23
23
  end
24
24
  end
25
25
 
26
- def base64_encode str
27
- [str].pack("m9999").chomp
28
- end
29
-
30
26
  end
31
27
  end
32
28
  end
@@ -13,7 +13,7 @@ module Flattr
13
13
 
14
14
  # @return [Integer]
15
15
  def self.patch
16
- 1
16
+ 2
17
17
  end
18
18
 
19
19
  # @return [String, NilClass]
@@ -0,0 +1,70 @@
1
+ require 'helper'
2
+
3
+ describe Flattr do
4
+ after do
5
+ Flattr.reset
6
+ end
7
+
8
+ describe '.respond_to?' do
9
+ it "should take an optional argument" do
10
+ Flattr.respond_to?(:new, true).should be_true
11
+ end
12
+ end
13
+
14
+ describe ".new" do
15
+ it "should return a Flattr::Client" do
16
+ Flattr.new.should be_a Flattr::Client
17
+ end
18
+ end
19
+
20
+ describe ".adapter" do
21
+ it "should return the default adapter" do
22
+ Flattr.adapter.should == Flattr::Config::DEFAULT_ADAPTER
23
+ end
24
+ end
25
+
26
+ describe ".adapter=" do
27
+ it "should set the adapter" do
28
+ Flattr.adapter = :typhoeus
29
+ Flattr.adapter.should == :typhoeus
30
+ end
31
+ end
32
+
33
+ describe ".endpoint" do
34
+ it "should return the default endpoint" do
35
+ Flattr.endpoint.should == Flattr::Config::DEFAULT_ENDPOINT
36
+ end
37
+ end
38
+
39
+ describe ".endpoint=" do
40
+ it "should set the endpoint" do
41
+ Flattr.endpoint = 'http://tumblr.com/'
42
+ Flattr.endpoint.should == 'http://tumblr.com/'
43
+ end
44
+ end
45
+
46
+ describe ".user_agent" do
47
+ it "should return the default user agent" do
48
+ Flattr.user_agent.should == Flattr::Config::DEFAULT_USER_AGENT
49
+ end
50
+ end
51
+
52
+ describe ".user_agent=" do
53
+ it "should set the user_agent" do
54
+ Flattr.user_agent = 'Custom User Agent'
55
+ Flattr.user_agent.should == 'Custom User Agent'
56
+ end
57
+ end
58
+
59
+ describe ".configure" do
60
+ Flattr::Config::VALID_OPTIONS_KEYS.each do |key|
61
+ it "should set the #{key}" do
62
+ Flattr.configure do |config|
63
+ config.send("#{key}=", key)
64
+ Flattr.send(key).should == key
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ end
data/spec/helper.rb ADDED
@@ -0,0 +1,38 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+ require 'flattr'
4
+ require 'rspec'
5
+ require 'webmock/rspec'
6
+
7
+ def a_delete(path, endpoint=Flattr.endpoint)
8
+ a_request(:delete, endpoint + path)
9
+ end
10
+
11
+ def a_get(path, endpoint=Flattr.endpoint)
12
+ a_request(:get, endpoint + path)
13
+ end
14
+
15
+ def a_post(path, endpoint=Flattr.endpoint)
16
+ a_request(:post, endpoint + path)
17
+ end
18
+
19
+ def a_put(path, endpoint=Flattr.endpoint)
20
+ a_request(:put, endpoint + path)
21
+ end
22
+
23
+ def stub_delete(path, endpoint=Flattr.endpoint)
24
+ stub_request(:delete, endpoint + path)
25
+ end
26
+
27
+ def stub_get(path, endpoint=Flattr.endpoint)
28
+ stub_request(:get, endpoint + path)
29
+ end
30
+
31
+ def stub_post(path, endpoint=Flattr.endpoint)
32
+ stub_request(:post, endpoint + path)
33
+ end
34
+
35
+ def stub_put(path, endpoint=Flattr.endpoint)
36
+ stub_request(:put, endpoint + path)
37
+ end
38
+
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.1
4
+ version: 0.2.2
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: 2011-12-10 00:00:00.000000000Z
13
+ date: 2011-12-11 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday
17
- requirement: &70096099213560 !ruby/object:Gem::Requirement
17
+ requirement: &70325557419160 !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: *70096099213560
25
+ version_requirements: *70325557419160
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: multi_json
28
- requirement: &70096099213060 !ruby/object:Gem::Requirement
28
+ requirement: &70325557417700 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,8 +33,74 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70096099213060
37
- description: Write a gem description
36
+ version_requirements: *70325557417700
37
+ - !ruby/object:Gem::Dependency
38
+ name: json
39
+ requirement: &70325557416920 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *70325557416920
48
+ - !ruby/object:Gem::Dependency
49
+ name: rake
50
+ requirement: &70325557406820 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *70325557406820
59
+ - !ruby/object:Gem::Dependency
60
+ name: rdiscount
61
+ requirement: &70325557406000 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *70325557406000
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec
72
+ requirement: &70325557405480 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: *70325557405480
81
+ - !ruby/object:Gem::Dependency
82
+ name: simplecov
83
+ requirement: &70325557405020 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: *70325557405020
92
+ - !ruby/object:Gem::Dependency
93
+ name: webmock
94
+ requirement: &70325557404500 !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ type: :development
101
+ prerelease: false
102
+ version_requirements: *70325557404500
103
+ description:
38
104
  email:
39
105
  - simon@smgt.me
40
106
  - joel.hansson@gmail.com
@@ -43,6 +109,8 @@ extensions: []
43
109
  extra_rdoc_files: []
44
110
  files:
45
111
  - .gitignore
112
+ - .rspec
113
+ - .travis.yml
46
114
  - Gemfile
47
115
  - LICENSE.md
48
116
  - README.md
@@ -77,7 +145,9 @@ files:
77
145
  - lib/flattr/thing.rb
78
146
  - lib/flattr/user.rb
79
147
  - lib/flattr/version.rb
80
- homepage: ''
148
+ - spec/flattr_spec.rb
149
+ - spec/helper.rb
150
+ homepage: http://github.com/simon/flattr
81
151
  licenses: []
82
152
  post_install_message:
83
153
  rdoc_options: []
@@ -100,5 +170,7 @@ rubyforge_project: flattr
100
170
  rubygems_version: 1.8.10
101
171
  signing_key:
102
172
  specification_version: 3
103
- summary: Write a gem summary
104
- test_files: []
173
+ summary: Flattr API wrapper
174
+ test_files:
175
+ - spec/flattr_spec.rb
176
+ - spec/helper.rb