Class: Gallery3
- Inherits:
-
Object
- Object
- Gallery3
- Defined in:
- lib/ruby-gallery3.rb
Instance Method Summary collapse
- #create_item(item_info) ⇒ Object
- #find_item(item) ⇒ Object
- #image_url_public?(item) ⇒ Boolean
-
#initialize(options = nil) ⇒ Gallery3
constructor
A new instance of Gallery3.
- #login?(user_info = nil) ⇒ Boolean
- #upload_file(upload_info) ⇒ Object
Constructor Details
#initialize(options = nil) ⇒ Gallery3
Returns a new instance of Gallery3.
9 10 11 12 13 14 15 16 |
# File 'lib/ruby-gallery3.rb', line 9 def initialize( = nil) if != nil = elsif file = File.read(Pathname.new(ENV["HOME"]).join(".gallery3.json")) = JSON.parse(file, :symbolize_names => true) end end |
Instance Method Details
#create_item(item_info) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ruby-gallery3.rb', line 54 def create_item(item_info) entity = JSON.generate(item_info[:entity]) item_id = [:rootItemId] item_id = item_info[:target_item][:id] if !item_info[:target_item].nil? url = "#{@options[:host]}#{@options[:base]}/rest/item/#{item_id}" response = RestClient::Request.execute( :method => :post, :url => url, :headers => {"X-Gallery-Request-Method" => "post"," X-Gallery-Request-Key" => [:requestKey]}, :payload => {'entity' => entity}) return JSON.parse(response, :symbolize_names => true) end |
#find_item(item) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ruby-gallery3.rb', line 36 def find_item(item) # url = "#{@options['host']}#{@options['base']}/rest/item/#{item[:id]}" # response = RestClient.get url, :headers => {"X-Gallery-Request-Key" => @options["requestKey"], "X-Gallery-Request-Method" => "get"} # item = JSON.parse(response) # return item url = "#{@options[:host]}#{@options[:base]}/rest/item/#{item[:id]}" response = RestClient::Request.execute( :method => :get, :url => url, :headers => { "X-Gallery-Request-Method" => "get", "X-Gallery-Request-Key" => [:requestKey] }) return JSON.parse(response, :symbolize_names => true) end |
#image_url_public?(item) ⇒ Boolean
104 105 106 |
# File 'lib/ruby-gallery3.rb', line 104 def image_url_public?(item) return find_item(item)[:entity][:file_url_public] end |
#login?(user_info = nil) ⇒ Boolean
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ruby-gallery3.rb', line 18 def login? (user_info = nil) url = "#{@options[:host]}#{@options[:base]}/rest" # response = RestClient.post(url, # {'user' => userInfo[:user], 'password' => userInfo[:password]}, # {"Content-Type" => "application/x-www-form-urlencoded", "X-Gallery-Request-Method" => "post"} ) user_info = { :user => [:user], :password => [:password] } response = RestClient::Request.execute( :method => :post, :url => url, :headers => {"Content-Type" => "application/x-www-form-urlencoded", "X-Gallery-Request-Method" => "post"}, :payload => user_info) return response end |
#upload_file(upload_info) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/ruby-gallery3.rb', line 71 def upload_file(upload_info) # entity = JSON.generate(uploadInfo[:entity]) item_id = [:rootItemId] item_id = upload_info[:target_item][:id] if !upload_info[:target_item].nil? entity = { :title => File.basename(upload_info[:file], File.extname(upload_info[:file])), :name => File.basename(upload_info[:file]).downcase.gsub(" ", "_"), :type => 'photo' } upload_info_entity = upload_info[:entity] if !upload_info_entity.nil? then entity[:title] = upload_info_entity[:title] if !upload_info_entity[:title].nil? entity[:name] = upload_info_entity[:name] if !upload_info_entity[:name].nil? end url = "#{@options[:host]}#{@options[:base]}/rest/item/#{item_id}" response = RestClient::Request.execute( :method => :post, :url => url, :headers => {"X-Gallery-Request-Method" => "post"," X-Gallery-Request-Key" => [:requestKey], 'Content-Type' => 'multipart/form-data'}, :payload => { 'entity' => JSON.generate(entity), :multipart => true, :file => File.new(upload_info[:file], 'rb')} ) return JSON.parse(response, :symbolize_names => true) end |