piwigo-api 0.1.0 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8bb322785be6cd6dc7badc8322d940011e3fda51d67ae22a633ce466c083b31b
4
- data.tar.gz: fa6d175bb4adc25dbb30f8721aaceb4664e9a4b78c17ddbc2dee6c4729d0e60e
3
+ metadata.gz: 1f0808e4bf6d4c5d9800c348b749a34b812d137a7268f76954895089127b0dc4
4
+ data.tar.gz: bba4ab540b38076e7c32e1e6d2b776e15a135ffd59a2d5f8b0e76c33b5d1ece9
5
5
  SHA512:
6
- metadata.gz: 9b9c04113aca32b50c383718303a682d0680472b25ce05dc28ab713930baf59d7b0b65e6cfea75e3e35bdd3ae122073a7ea49b97e9ab81b0ca10b29846b864d7
7
- data.tar.gz: 1cfe5a89b68ce944fb06f5c8d311bff2e41b40babe5c65534014cea268d68163f33775a2af91f7f322ee79a3385b2601cf1dd6c3c339d3416062997c5fc149c3
6
+ metadata.gz: 0b5f0499e2d5f445b023f3252d6b4d10802e5374c19be951b872d59bc5e64e33b7c0f85c1dffc3e3503b4b98ff0faa71928e36d0223f540b73530763331b1740
7
+ data.tar.gz: 8d37ee9536426d15f36c4c25ca12cd1c0019819410af4332bc6515c9f9a9dc57329532fdd8be0e89c24581993ea1766a129ac4738e6b187b133e2c69bb35ebcf
@@ -1,44 +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}}
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/.vscode/launch.json CHANGED
@@ -1,15 +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
- ]
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
15
  }
data/CHANGELOG.md CHANGED
@@ -1,7 +1,12 @@
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]
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]
8
+
9
+
10
+ 0.1.1 - 2019-11-16
11
+ - Initial Version, supports login/logout against a piwigo server
12
+ - Fixing spec consistency issues
@@ -1,76 +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
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
76
  end
@@ -1,3 +1,3 @@
1
1
  module Piwigo
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/main.rb CHANGED
@@ -1,8 +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
-
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
8
  puts "END"
data/piwigo-api.gemspec CHANGED
@@ -10,12 +10,12 @@ Gem::Specification.new do |spec|
10
10
 
11
11
  spec.summary = %q{Ruby gem to interact with the Piwigo API}
12
12
  spec.description = %q{Ruby gem to interact with the Piwigo API}
13
- spec.homepage = "https://github.com/kkdad/ruby-piwigo"
13
+ spec.homepage = "https://github.com/kkdad/piwigo-api"
14
14
  spec.license = "MIT"
15
15
 
16
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"
17
+ spec.metadata["source_code_uri"] = "https://github.com/kkdad/piwigo-api"
18
+ spec.metadata["changelog_uri"] = "https://github.com/kkdad/piwigo-api/CHANGELOG.md"
19
19
 
20
20
  # Specify which files should be added to the gem when it is released.
21
21
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: piwigo-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Gilbert
@@ -104,13 +104,13 @@ files:
104
104
  - lib/piwigo/version.rb
105
105
  - main.rb
106
106
  - piwigo-api.gemspec
107
- homepage: https://github.com/kkdad/ruby-piwigo
107
+ homepage: https://github.com/kkdad/piwigo-api
108
108
  licenses:
109
109
  - MIT
110
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
111
+ homepage_uri: https://github.com/kkdad/piwigo-api
112
+ source_code_uri: https://github.com/kkdad/piwigo-api
113
+ changelog_uri: https://github.com/kkdad/piwigo-api/CHANGELOG.md
114
114
  post_install_message:
115
115
  rdoc_options: []
116
116
  require_paths: