ruby-gallery3 0.0.1

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/ruby-gallery3.rb +109 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 74d66e0d5117f6912eb8739e4de2769c4a7503a4
4
+ data.tar.gz: 369888b77e8c37695dc9abff9ad5f23fea7c72c5
5
+ SHA512:
6
+ metadata.gz: 6022367de57f250fef9707ca0ed679ee9ed041ab378a04a254c52bfef77442cda402457d9af1d574f5a7507745b9d3a16ebe256bbaf280a7d39c123cb6b06fcb
7
+ data.tar.gz: 68e83dad36ff43f9c5aab80aedc5defbb47a140f487ffedfa74938e1e33c5565e65ca7da39c137fd11a5110e0f2bbf84aff86c414c6d526163291fba979e8803
@@ -0,0 +1,109 @@
1
+ require 'json'
2
+ require 'pathname'
3
+ require 'rest_client'
4
+
5
+
6
+
7
+ class Gallery3
8
+
9
+ def initialize(options = nil)
10
+ if options != nil
11
+ @options = options
12
+ elsif
13
+ file = File.read(Pathname.new(ENV["HOME"]).join(".gallery3.json"))
14
+ @options = JSON.parse(file, :symbolize_names => true)
15
+ end
16
+ end
17
+
18
+ def login? (user_info = nil)
19
+ url = "#{@options[:host]}#{@options[:base]}/rest"
20
+ # response = RestClient.post(url,
21
+ # {'user' => userInfo[:user], 'password' => userInfo[:password]},
22
+ # {"Content-Type" => "application/x-www-form-urlencoded", "X-Gallery-Request-Method" => "post"} )
23
+ user_info = {
24
+ :user => @options[:user],
25
+ :password => @options[:password]
26
+ }
27
+
28
+ response = RestClient::Request.execute(
29
+ :method => :post,
30
+ :url => url,
31
+ :headers => {"Content-Type" => "application/x-www-form-urlencoded", "X-Gallery-Request-Method" => "post"},
32
+ :payload => user_info)
33
+ return response
34
+ end
35
+
36
+ def find_item(item)
37
+ # url = "#{@options['host']}#{@options['base']}/rest/item/#{item[:id]}"
38
+ # response = RestClient.get url, :headers => {"X-Gallery-Request-Key" => @options["requestKey"], "X-Gallery-Request-Method" => "get"}
39
+ # item = JSON.parse(response)
40
+ # return item
41
+ url = "#{@options[:host]}#{@options[:base]}/rest/item/#{item[:id]}"
42
+
43
+ response = RestClient::Request.execute(
44
+ :method => :get,
45
+ :url => url,
46
+ :headers => {
47
+ "X-Gallery-Request-Method" => "get",
48
+ "X-Gallery-Request-Key" => @options[:requestKey]
49
+ })
50
+ return JSON.parse(response, :symbolize_names => true)
51
+
52
+ end
53
+
54
+ def create_item(item_info)
55
+ entity = JSON.generate(item_info[:entity])
56
+
57
+ item_id = @options[:rootItemId]
58
+ item_id = item_info[:target_item][:id] if !item_info[:target_item].nil?
59
+
60
+ url = "#{@options[:host]}#{@options[:base]}/rest/item/#{item_id}"
61
+
62
+ response = RestClient::Request.execute(
63
+ :method => :post,
64
+ :url => url,
65
+ :headers => {"X-Gallery-Request-Method" => "post"," X-Gallery-Request-Key" => @options[:requestKey]},
66
+ :payload => {'entity' => entity})
67
+
68
+ return JSON.parse(response, :symbolize_names => true)
69
+ end
70
+
71
+ def upload_file(upload_info)
72
+ # entity = JSON.generate(uploadInfo[:entity])
73
+ item_id = @options[:rootItemId]
74
+ item_id = upload_info[:target_item][:id] if !upload_info[:target_item].nil?
75
+
76
+ entity = {
77
+ :title => File.basename(upload_info[:file], File.extname(upload_info[:file])),
78
+ :name => File.basename(upload_info[:file]).downcase.gsub(" ", "_"),
79
+ :type => 'photo'
80
+ }
81
+
82
+ upload_info_entity = upload_info[:entity]
83
+
84
+ if !upload_info_entity.nil? then
85
+ entity[:title] = upload_info_entity[:title] if !upload_info_entity[:title].nil?
86
+ entity[:name] = upload_info_entity[:name] if !upload_info_entity[:name].nil?
87
+ end
88
+
89
+ url = "#{@options[:host]}#{@options[:base]}/rest/item/#{item_id}"
90
+
91
+ response = RestClient::Request.execute(
92
+ :method => :post,
93
+ :url => url,
94
+ :headers => {"X-Gallery-Request-Method" => "post"," X-Gallery-Request-Key" => @options[:requestKey], 'Content-Type' => 'multipart/form-data'},
95
+ :payload => {
96
+ 'entity' => JSON.generate(entity),
97
+ :multipart => true,
98
+ :file => File.new(upload_info[:file], 'rb')}
99
+ )
100
+
101
+ return JSON.parse(response, :symbolize_names => true)
102
+ end
103
+
104
+ def image_url_public?(item)
105
+ return find_item(item)[:entity][:file_url_public]
106
+ end
107
+
108
+ end
109
+
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-gallery3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - SungKwang Song
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-30 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: ruby based gallery3 client library gem
14
+ email: saltfactory@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/ruby-gallery3.rb
20
+ homepage: https://github.com/saltfactory/ruby-gallery3
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.4.3
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Gallery3 Client Library via Ruby
44
+ test_files: []