smgt / flattr Goto Github PK
View Code? Open in Web Editor NEWA ruby gem wrapping Flattrs REST API
License: MIT License
A ruby gem wrapping Flattrs REST API
License: MIT License
Hi Simon,
I recently found that creating new things no longer works for me.
I was still using the 0.3.0 version of the gem so first I upgraded to the latest 0.3.5 plus I upgraded to the latest Faraday and Multi_JSON gems.
However I still get this repsonse from my ruby script that worked fine until some days ago:
/Library/Ruby/Gems/1.8/gems/flattr-0.3.5/lib/flattr/response/raise_client_error.rb:15:in `on_complete': Not allowed to specify user for connection URL:s. (Flattr::Error::BadRequest)
from /Library/Ruby/Gems/1.8/gems/faraday-0.7.6/lib/faraday/response.rb:9:in `call'
from /Library/Ruby/Gems/1.8/gems/faraday-0.7.6/lib/faraday/response.rb:62:in `on_complete'
from /Library/Ruby/Gems/1.8/gems/faraday-0.7.6/lib/faraday/response.rb:8:in `call'
from /Library/Ruby/Gems/1.8/gems/flattr-0.3.5/lib/flattr/request/oauth2.rb:9:in `call'
from /Library/Ruby/Gems/1.8/gems/faraday-0.7.6/lib/faraday/connection.rb:210:in `run_request'
from /Library/Ruby/Gems/1.8/gems/faraday-0.7.6/lib/faraday/connection.rb:98:in `post'
from /Library/Ruby/Gems/1.8/gems/flattr-0.3.5/lib/flattr/request.rb:34:in `send'
from /Library/Ruby/Gems/1.8/gems/flattr-0.3.5/lib/flattr/request.rb:34:in `request'
from /Library/Ruby/Gems/1.8/gems/flattr-0.3.5/lib/flattr/request.rb:18:in `post'
from /Library/Ruby/Gems/1.8/gems/flattr-0.3.5/lib/flattr/client/things.rb:54:in `thing_new'
from flattr_submit_thing.rb:66
It's not complaining about authentication or anything so I wonder if there were changes that are out of my scope? Has anything changed in the API recently?
As stated above - I had no changes in my script :(
Regards,
Tobi
Flattr supports basic auth to authenticate a user to the api. Would be nice if the gem supported basic auth.
You can set the redirect_uri on
flattr.authorize_url(:scope => "email", :redirect_uri => "http://localhost:8000/oauth_endpoint")
but this is not possible on
flattr.get_access_token(code)
oauth2 fails with missing redirect_uri on querying access_token.
Patch:
diff --git a/lib/flattr/oauth2.rb b/lib/flattr/oauth2.rb
index ca8afd2..fa53a90 100644
--- a/lib/flattr/oauth2.rb
+++ b/lib/flattr/oauth2.rb
@@ -24,11 +24,12 @@ module Flattr
"#{authorize_endpoint}/?#{query_string}"
end
- def get_access_token(code)
+ def get_access_token(code, opts = {})
+ default_options = {
- response = post(token_endpoint, {
:code => code.strip,
:grant_type => 'authorization_code'
- },{
+ }
+ response = post(token_endpoint, default_options.merge(opts), {
:headers => {
:authorization => "Basic #{Flattr::Client.base64_encode("#{client_id}:#{client_secret}")}"
}}
now it is possible to set the redirect_uri on get_access_token:
access_token = flattr.get_access_token(code, :redirect_uri => "http://localhost:8000/oauth_endpoint")
Hi there,
this seems like a real noob problem but I just can't get it running.
I used your samples to get a code with which I can order access tokens. However I don't get an access token when I use the following code?!
# code has already been requested in another script with flattr.authorize_url(:scope => "thing")
code = "YXZ"
Flattr.configure do |config|
# get these from the command line
config.client_id = options[:apikey]
config.client_secret = options[:sharedsecret]
end
flattr = Flattr.new
token = flattr.get_access_token code
# nil - WTF?
puts "new access_token #{token}"
thing_opts = {}
a = flattr.thing_new("http://gatogatogato.ch/xxxxxxxxx",thing_opts)
# not good - I'm not authenticated :(
puts a.attrs['error_description']
What am I doing wrong? Been looking through all the files in the gem but I can't find anything that helps me here. :(
Regards,
gato
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.