piwigo-api 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8bb322785be6cd6dc7badc8322d940011e3fda51d67ae22a633ce466c083b31b
4
+ data.tar.gz: fa6d175bb4adc25dbb30f8721aaceb4664e9a4b78c17ddbc2dee6c4729d0e60e
5
+ SHA512:
6
+ metadata.gz: 9b9c04113aca32b50c383718303a682d0680472b25ce05dc28ab713930baf59d7b0b65e6cfea75e3e35bdd3ae122073a7ea49b97e9ab81b0ca10b29846b864d7
7
+ data.tar.gz: 1cfe5a89b68ce944fb06f5c8d311bff2e41b40babe5c65534014cea268d68163f33775a2af91f7f322ee79a3385b2601cf1dd6c3c339d3416062997c5fc149c3
@@ -0,0 +1,44 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ pull_request:
5
+ branches:
6
+ - master
7
+ push:
8
+ branches:
9
+ - master
10
+
11
+ jobs:
12
+ build:
13
+ name: Build + Publish
14
+ runs-on: ubuntu-latest
15
+
16
+ steps:
17
+ - uses: actions/checkout@master
18
+ - name: Set up Ruby 2.6
19
+ uses: actions/setup-ruby@v1
20
+ with:
21
+ version: 2.6.x
22
+
23
+ - name: Publish to GPR
24
+ run: |
25
+ mkdir -p $HOME/.gem
26
+ touch $HOME/.gem/credentials
27
+ chmod 0600 $HOME/.gem/credentials
28
+ printf -- "---\n:github: Bearer ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
29
+ gem build *.gemspec
30
+ gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
31
+ env:
32
+ GEM_HOST_API_KEY: ${{secrets.GPR_AUTH_TOKEN}}
33
+ OWNER: KKDad
34
+
35
+ - name: Publish to RubyGems
36
+ run: |
37
+ mkdir -p $HOME/.gem
38
+ touch $HOME/.gem/credentials
39
+ chmod 0600 $HOME/.gem/credentials
40
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
41
+ gem build *.gemspec
42
+ gem push *.gem
43
+ env:
44
+ GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}}
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.gem
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.5
7
+ before_install: gem install bundler -v 2.0.2
@@ -0,0 +1,15 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+
8
+ {
9
+ "name": "Debug Local File",
10
+ "type": "Ruby",
11
+ "request": "launch",
12
+ "program": "${workspaceRoot}/main.rb"
13
+ }
14
+ ]
15
+ }
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in piwigo.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,48 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ piwigo-api (0.1.0)
5
+ http (~> 4.2)
6
+ logger (~> 1.4)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.7.0)
12
+ public_suffix (>= 2.0.2, < 5.0)
13
+ domain_name (0.5.20190701)
14
+ unf (>= 0.0.5, < 1.0.0)
15
+ ffi (1.11.2-x64-mingw32)
16
+ ffi-compiler (1.0.1)
17
+ ffi (>= 1.0.0)
18
+ rake
19
+ http (4.2.0)
20
+ addressable (~> 2.3)
21
+ http-cookie (~> 1.0)
22
+ http-form_data (~> 2.0)
23
+ http-parser (~> 1.2.0)
24
+ http-cookie (1.0.3)
25
+ domain_name (~> 0.5)
26
+ http-form_data (2.1.1)
27
+ http-parser (1.2.1)
28
+ ffi-compiler (>= 1.0, < 2.0)
29
+ logger (1.4.1)
30
+ minitest (5.13.0)
31
+ public_suffix (4.0.1)
32
+ rake (10.5.0)
33
+ unf (0.1.4)
34
+ unf_ext
35
+ unf_ext (0.0.7.6)
36
+
37
+ PLATFORMS
38
+ ruby
39
+ x64-mingw32
40
+
41
+ DEPENDENCIES
42
+ bundler (~> 2.0)
43
+ minitest (~> 5.0)
44
+ piwigo-api!
45
+ rake (~> 10.0)
46
+
47
+ BUNDLED WITH
48
+ 2.0.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Adrian Gilbert
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Piwigo-API
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/piwigo`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'piwigo-api'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install piwigo-api
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kkdad/piwigo.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "piwigo"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,76 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'json'
4
+ require 'logger'
5
+
6
+ module Piwigo
7
+ # Class to hold the Piwigo session the rest of the API needs to pass in order to access the API
8
+ class Session
9
+
10
+ def session_id
11
+ @session_id
12
+ end
13
+
14
+ # Instantion a new Session object
15
+ # @param [Logger] logger logger to output debug messages to (Optional)
16
+ def initialize(logger: nil)
17
+ @session_id=nil
18
+ @uri=nil
19
+ @logger = logger || Logger.new(STDOUT)
20
+ end
21
+
22
+ # Log into the piwigo API and grab the session id for subsequent calls.
23
+ # @param [string] piwigo - host to connect to. Can be fqdn or ip.
24
+ # @param [string] username - user to connect as
25
+ # @param [string] password - password for user
26
+ # @param [boolean] https - Use HTTPS?
27
+ def login(host, username, password, https: true)
28
+
29
+ raise "host should not be nil" if host.nil?
30
+ raise "username should not be nil" if username.nil?
31
+
32
+ begin
33
+
34
+ @uri = https ? URI::HTTPS.build(host: host, path: "/ws.php", query: "format=json") :
35
+ URI::HTTP.build(host: host, path: "/ws.php", query: "format=json")
36
+
37
+ # Create the HTTP objects
38
+ http = Net::HTTP.new(@uri.host, @uri.port)
39
+ request = Net::HTTP::Post.new(@uri.request_uri)
40
+ request.body = "method=pwg.session.login&username=#{username}&password=#{password}"
41
+
42
+ # Send the request
43
+ response = http.request(request)
44
+
45
+ if response.code == '200'
46
+ @logger.info "Login succeeded: #{response.body}"
47
+ @session_id = response.response['set-cookie'].split(';').select { |i| i.strip.start_with? "pwg_id" }
48
+ return true
49
+ else
50
+ @logger.error "Login failed: #{response.body}"
51
+ @session_id = nil
52
+ @uri = nil
53
+ end
54
+
55
+ rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
56
+ @logger.error "Login failed: #{e.messages}"
57
+ end
58
+ false
59
+ end
60
+
61
+ def logout
62
+ raise "login must be successfully called before logout" if @uri.nil?
63
+
64
+ # Create the HTTP objects
65
+ http = Net::HTTP.new(@uri.host, @uri.port)
66
+ request = Net::HTTP::Get.new(@uri.request_uri + "&method=pwg.session.logout")
67
+ request['Cookie'] = @session_id
68
+
69
+ # Send the request
70
+ response = http.request(request)
71
+ @logger.info "Logout succeeded: #{response.body}" if response.code == '200'
72
+ @session_id = nil
73
+ @uri = nil
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,3 @@
1
+ module Piwigo
2
+ VERSION = "0.1.0"
3
+ end
data/lib/piwigo.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "piwigo/version"
2
+
3
+ module Piwigo
4
+ class Error < StandardError; end
5
+ # Your code goes here...
6
+ end
data/main.rb ADDED
@@ -0,0 +1,8 @@
1
+ require_relative 'lib/piwigo/session'
2
+
3
+ puts "BEGIN"
4
+ session = Piwigo::Session.new
5
+ session.login('10.100.230.78', 'Adrian', 'secret', https: false)
6
+ session.logout
7
+
8
+ puts "END"
@@ -0,0 +1,35 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "piwigo/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "piwigo-api"
7
+ spec.version = Piwigo::VERSION
8
+ spec.authors = ["Adrian Gilbert"]
9
+ spec.email = ["adrian@gilbert.ca"]
10
+
11
+ spec.summary = %q{Ruby gem to interact with the Piwigo API}
12
+ spec.description = %q{Ruby gem to interact with the Piwigo API}
13
+ spec.homepage = "https://github.com/kkdad/ruby-piwigo"
14
+ spec.license = "MIT"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/kkdad/piwigo-ruby"
18
+ spec.metadata["changelog_uri"] = "https://github.com/kkdad/piwigo-ruby/CHANGELOG.md"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 2.0"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "minitest", "~> 5.0"
32
+
33
+ spec.add_runtime_dependency "logger", "~>1.4"
34
+ spec.add_runtime_dependency "http", "~>4.2"
35
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: piwigo-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Adrian Gilbert
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-11-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: logger
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.4'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: http
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.2'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.2'
83
+ description: Ruby gem to interact with the Piwigo API
84
+ email:
85
+ - adrian@gilbert.ca
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".github/workflows/gempush.yml"
91
+ - ".gitignore"
92
+ - ".travis.yml"
93
+ - ".vscode/launch.json"
94
+ - CHANGELOG.md
95
+ - Gemfile
96
+ - Gemfile.lock
97
+ - LICENSE.txt
98
+ - README.md
99
+ - Rakefile
100
+ - bin/console
101
+ - bin/setup
102
+ - lib/piwigo.rb
103
+ - lib/piwigo/session.rb
104
+ - lib/piwigo/version.rb
105
+ - main.rb
106
+ - piwigo-api.gemspec
107
+ homepage: https://github.com/kkdad/ruby-piwigo
108
+ licenses:
109
+ - MIT
110
+ metadata:
111
+ homepage_uri: https://github.com/kkdad/ruby-piwigo
112
+ source_code_uri: https://github.com/kkdad/piwigo-ruby
113
+ changelog_uri: https://github.com/kkdad/piwigo-ruby/CHANGELOG.md
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubygems_version: 3.0.3
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Ruby gem to interact with the Piwigo API
133
+ test_files: []