piwigo-api 0.2.0 → 0.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5051a29ebbe23995bb4c2d6436d6534b197f1b3794f7f857e0678e612d544501
4
- data.tar.gz: f0c5dc53eede301abf914eb04fecb42e3c607281786939ef51db3dc50a6c8e98
3
+ metadata.gz: 1108a31f234ef9bb5c9f99091378eb6d6d114eedd26b4e64329e2f803554b612
4
+ data.tar.gz: c30f56e0cb40c0b93cba86bffcd3d14d5f00d0aec28bd861707f8d8e8ef1406d
5
5
  SHA512:
6
- metadata.gz: 0fa2225cd04231a474299be116ff723a7ecbc70f44ada895041adfa2e47131663d08f60b399dd2ca98eb5e8f24ebf403195f2ff8aaf929d2e17e63bb7345c7cb
7
- data.tar.gz: 4dfb369883eadfe868eaa6853a9c3c70661fef1ad9fd01b57011cf6e30454c5c56caf559f855465939ec9a2c9ab11f7c21a01eb99d6c0c063129441cdef340c1
6
+ metadata.gz: 71c2c6bd8420c15e1590339612c512e5c589819d005fd0b569f850b8ab7adcdc407d852aadff78cb28d97e6976f1941a232c508dbf1204a42c9691234ab56b52
7
+ data.tar.gz: c248f198a9d17fa71e29d7e53cd98e89087cb756898139fef94ddcd7ae30956d52c4ecc67fc9efd8a6cc2a93ed7c6c265a0f6deb8e47f85bd2237cf45e37f19e
@@ -0,0 +1,20 @@
1
+ name: Ruby
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+
8
+ runs-on: ubuntu-latest
9
+
10
+ steps:
11
+ - uses: actions/checkout@v1
12
+ - name: Set up Ruby 2.6
13
+ uses: actions/setup-ruby@v1
14
+ with:
15
+ ruby-version: 2.6.x
16
+ - name: Build and test with Rake
17
+ run: |
18
+ gem install bundler
19
+ bundle install --jobs 4 --retry 3
20
+ bundle exec rake
data/CHANGELOG.md CHANGED
@@ -6,8 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ 0.3.0 - 2019-11-17
10
+ - Added a documentation URL pointing to rubydoc.info
11
+ - Added build badges
12
+ - Added ability to page though the images in an album
13
+
9
14
  0.2.0 - 2019-11-17
10
- - Refactored the Session to make iteasier to use
15
+ - Refactored the Session to make it easier to use
11
16
  - Support adding/deleting & listing albums
12
17
 
13
18
  0.1.1 - 2019-11-16
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Piwigo-API
2
2
 
3
- Piwigo is open source web application to manage your collection of photos, and other medias. Piwigo provides an API for interacting with it.
3
+ ![](https://github.com/kkdad/piwigo-api/workflows/Ruby/badge.svg) ![](https://github.com/kkdad/piwigo-api/workflows/Ruby%20Gem/badge.svg) [![Gem Version](https://badge.fury.io/rb/piwigo-api.svg)](https://badge.fury.io/rb/piwigo-api)
4
+
5
+ [Piwigo](https://piwigo.org/) is open source web application to manage your collection of photos, and other medias. Piwigo provides an API for interacting with it.
4
6
 
5
7
  This is a ruby-based client for interacting with a Piwigo instance using the Piwigo API.
6
8
 
@@ -26,8 +28,7 @@ Just include 'piwigo/session' and the related classes, then querying Piwigo is f
26
28
 
27
29
  # Get the second album and all of it's children
28
30
 
29
-
30
- ```
31
+ ```ruby
31
32
  require 'piwigo/session'
32
33
  require 'piwigo/albums'
33
34
 
@@ -39,8 +40,11 @@ end
39
40
  ```
40
41
 
41
42
  # Add a new album
42
- ```
43
- session = Piwigo::Session.login('10.100.230.78', 'Adrian', 'secret', https: false)
43
+ ```ruby
44
+ require 'piwigo/session'
45
+ require 'piwigo/albums'
46
+
47
+ session = Piwigo::Session.login('10.100.230.78', 'Adrian', 'mypassword', https: false)
44
48
  unless session.nil?
45
49
  album = Piwigo::Albums::Album.new
46
50
  album.name = "My First Album"
@@ -48,6 +52,19 @@ unless session.nil?
48
52
  end
49
53
  ```
50
54
 
55
+ # List the Contents of an Album
56
+
57
+ ```ruby
58
+ require 'piwigo/session'
59
+ require 'piwigo/images'
60
+
61
+ session = Piwigo::Session.login('mypiwigo.fqdn', 'Adrian', 'mypassword', https: false)
62
+ unless session.nil?
63
+ results = Piwigo::Images.getImages(session, album_id: 4)
64
+
65
+ results[:images].each { |image| p "#{image.id}, #{image.name} - #{image.element_url}" }
66
+ end
67
+ ```
51
68
 
52
69
  ## Development
53
70
 
data/lib/piwigo/albums.rb CHANGED
@@ -180,8 +180,6 @@ module Piwigo
180
180
  logger.error "Album delete: #{e.messages}"
181
181
  false
182
182
  end
183
- end
184
-
185
-
183
+ end
186
184
  end
187
185
  end
@@ -0,0 +1,117 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'json'
4
+ require 'logger'
5
+
6
+ # Piwigo organizes images by albums. The album tree has unlimted depth and each photo can belong to multiple albums. The Piwigo API
7
+ # refers to a Album as a Category.
8
+ module Piwigo
9
+ class Images
10
+ class Image
11
+ # @return [Number] Unique ID idenifying this ie
12
+ attr_accessor :id
13
+
14
+ # @return [Number] Width of the image in pixels
15
+ attr_accessor :width
16
+
17
+ # @return [Number] Height of the image in pixels
18
+ attr_accessor :height
19
+
20
+ # @return [Number] Number of times the image has been viewed
21
+ attr_accessor :hit
22
+
23
+ # @return [String] Filename for the image
24
+ attr_accessor :file
25
+
26
+ # @return [String] Name of the image
27
+ attr_accessor :name
28
+
29
+ # @return [String] Comments about the image
30
+ attr_accessor :comment
31
+
32
+ # @return [DateTime] DateTime when the image was taken
33
+ attr_accessor :date_creation
34
+
35
+ # @return [DateTime] DateTime when the image was uploaded to Piwigo
36
+ attr_accessor :date_available
37
+
38
+ # @return [String] URL to the image page
39
+ attr_accessor :page_url
40
+
41
+ # @return [String] URL to the image itself
42
+ attr_accessor :element_url
43
+
44
+ # @return [Array<String>] Links to different sizes of the image
45
+ attr_accessor :derivatives
46
+
47
+ # @return [<Type>] List of all of the Albums this image is in
48
+ attr_accessor :categories
49
+
50
+ def initialize(hash: nil)
51
+ hash.each { |key, value| send("#{key}=", value) } unless hash.nil?
52
+ end
53
+ end
54
+
55
+ class Paging
56
+ # @return [Number] Page number of the results
57
+ attr_accessor :page
58
+
59
+ # @return [Number] Number of images requesed per page
60
+ attr_accessor :per_page
61
+
62
+ # @return [Number] Number of Images on this page. When this is less then the number per page, then there are no more results.
63
+ attr_accessor :count
64
+
65
+ # @return [Number] Total number of images across all pages
66
+ attr_accessor :total_count
67
+
68
+ def initialize(hash: nil)
69
+ hash.each { |key, value| send("#{key}=", value) } unless hash.nil?
70
+ end
71
+ end
72
+
73
+ # Returns elements for the corresponding categories.
74
+ # order comma separated fields for sorting
75
+ #
76
+ # @param [Session] session
77
+ # @param [Number] album_id - Can be empty if recursive is true.
78
+ # @param [Boolean] recursive - Include images from child albums
79
+ # @param [Number] per_page - Number of items to include per page
80
+ # @param [Number] page - Page to retrieve
81
+ # @param [String] order - One or more of id, file, name, hit, rating_score, date_creation, date_available or random
82
+ # @param [Logger] logger logger to output debug messages to (Optional)
83
+ #
84
+ # @return [Hash] <description>
85
+ def self.getImages(session, album_id: nil, recursive: nil, per_page: 100, page: 0, order: nil, logger: nil)
86
+ raise "Invalid session" if session.uri.nil?
87
+ logger = logger || Logger.new(STDOUT)
88
+
89
+ begin
90
+ http = Net::HTTP.new(session.uri.host, session.uri.port)
91
+ request = Net::HTTP::Post.new(session.uri.request_uri)
92
+ request.body = "method=pwg.categories.getImages"
93
+ request.body.concat "&cat_id=#{album_id}" unless album_id.nil?
94
+ request.body.concat "&recursive=#{recursive}" unless recursive.nil?
95
+ request.body.concat "&per_page=#{per_page}" unless album_id.nil?
96
+ request.body.concat "&order=#{order}" unless order.nil?
97
+ request['Cookie'] = [session.id]
98
+
99
+ # Send the request
100
+ response = http.request(request)
101
+ if response.code == '200'
102
+ data = JSON.parse(response.body)
103
+ paging = Paging.new hash: data['result']['paging']
104
+ images = data['result']['images'].map{ |hash| Image.new(hash: hash) }
105
+ logger.info "Image List succeeded: #{images.size} images retrieved."
106
+ { :paging => paging, :images => images }
107
+ else
108
+ nil
109
+ end
110
+ rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
111
+ logger.error "Image List failed: #{e.messages}"
112
+ nil
113
+ end
114
+ end
115
+
116
+ end
117
+ end
@@ -1,3 +1,3 @@
1
1
  module Piwigo
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/piwigo-api.gemspec CHANGED
@@ -16,6 +16,7 @@ Gem::Specification.new do |spec|
16
16
  spec.metadata["homepage_uri"] = spec.homepage
17
17
  spec.metadata["source_code_uri"] = "https://github.com/kkdad/piwigo-api"
18
18
  spec.metadata["changelog_uri"] = "https://github.com/kkdad/piwigo-api/CHANGELOG.md"
19
+ spec.metadata["documentation_uri"] = "https://rubydoc.info/github/KKDad/piwigo-api/master"
19
20
 
20
21
  # Specify which files should be added to the gem when it is released.
21
22
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: piwigo-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Gilbert
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-17 00:00:00.000000000 Z
11
+ date: 2019-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -90,6 +90,7 @@ extensions: []
90
90
  extra_rdoc_files: []
91
91
  files:
92
92
  - ".github/workflows/gempush.yml"
93
+ - ".github/workflows/ruby.yml"
93
94
  - ".gitignore"
94
95
  - ".travis.yml"
95
96
  - ".vscode/launch.json"
@@ -103,6 +104,7 @@ files:
103
104
  - bin/setup
104
105
  - lib/piwigo.rb
105
106
  - lib/piwigo/albums.rb
107
+ - lib/piwigo/images.rb
106
108
  - lib/piwigo/session.rb
107
109
  - lib/piwigo/version.rb
108
110
  - piwigo-api.gemspec
@@ -113,6 +115,7 @@ metadata:
113
115
  homepage_uri: https://github.com/kkdad/piwigo-api
114
116
  source_code_uri: https://github.com/kkdad/piwigo-api
115
117
  changelog_uri: https://github.com/kkdad/piwigo-api/CHANGELOG.md
118
+ documentation_uri: https://rubydoc.info/github/KKDad/piwigo-api/master
116
119
  post_install_message:
117
120
  rdoc_options: []
118
121
  require_paths: