photo / openphoto-ruby Goto Github PK
View Code? Open in Web Editor NEWA Ruby OAuth client for OpenPhoto
Home Page: http://theopenphotoproject.org
A Ruby OAuth client for OpenPhoto
Home Page: http://theopenphotoproject.org
Is it normal that, as opposed to POST, the GET method doesn’t take parameters in the params
hash?
client.connect( :get, '/hello.json', { 'foo' => 'bar' } ).json
# => {"message"=>"Hello, world!", "code"=>200, "result"=>{"__route__"=>"/hello.json"}}
client.connect( :get, '/hello.json?foo=bar' ).json
# => {"message"=>"Hello, world!", "code"=>200, "result"=>{"__route__"=>"/hello.json", "foo"=>"bar"}}
See openphoto/openphoto-python#5
I'm running the example code, having defined @site
as "http://trovebox.com" and all other instance variables as required. I have an account on trovebox and generated all tokens.
require 'rubygems'
require 'openphoto-ruby'
@client = Openphoto::Client.new(@site, @consumer_key, @consumer_secret, @access_token, @access_token_secret)
photo = @client.connect(:post, "/photo/upload.json", {"photo"=>"/tmp/photo.png", "permission"=>"1", "title"=>"test upload"})
puts "#{photo.message} #{@site}/photo/#{photo.result["id"]}/view"
I get the following error:
[rekado@mango openphoto-ruby]$ bundle exec ruby test-upload.rb
/home/rekado/dev/openphoto-ruby/vendor/ruby/1.9.1/gems/json-1.7.6/lib/json/common.rb:155:in `initialize': A JSON text must at least contain two octets! (JSON::ParserError)
from /home/rekado/dev/openphoto-ruby/vendor/ruby/1.9.1/gems/json-1.7.6/lib/json/common.rb:155:in `new'
from /home/rekado/dev/openphoto-ruby/vendor/ruby/1.9.1/gems/json-1.7.6/lib/json/common.rb:155:in `parse'
from /home/rekado/dev/openphoto-ruby/lib/openphoto-ruby.rb:50:in `json'
from /home/rekado/dev/openphoto-ruby/lib/openphoto-ruby.rb:54:in `result'
from test-upload.rb:25:in `<main>'
It appears that the result is empty, so the parse fails. Are there any obvious problems with the code?
The library currently encodes the image inline as base64 in the post data.
It would be better to send a multipart/related request instead.
One way to do it would be to add an upload method, eg:
module Openphoto
require 'net/http/post/multipart'
class Client
def upload photo, params = {}
params["photo"] = UploadIO.new(File.open(photo), "image/jpeg", File.basename(photo))
access_token = prepare_access_token
request = Net::HTTP::Post::Multipart.new('/photo/upload.json', params)
access_token.sign! request
url = URI.parse @hostname
response = Net::HTTP.start(url.host, url.port, :use_ssl => true) do |http|
http.request request
end
response.extend Openphoto::Response
response
end
end
end
(used in https://github.com/jo/trovebox-uploader)
One could also enhance the connect method.
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.