osuny_api 0.2.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: f1a3d2e6cd60019b441bb74ea0a77416530c7db75ecf2ec8abfb0c7628b39bde
4
+ data.tar.gz: 5220e60f717e00ec7fa04fe76be021b3432578d83cf5381f94b79d779ad888c1
5
+ SHA512:
6
+ metadata.gz: 92967da0c264a577a5ec3c8a894042fd56df180d9657a79aa64aee964ad2007fdfb82f677f40d7780af9a231842f71d2515fef791a3e5c49d3e2353157c2c994
7
+ data.tar.gz: f232a0fb21d4e152450abddfe081daf801525332c6da3a274b8b63f8cac09658a9618880c9e31785abf1c7e43195e7995375b3923b8d672bd50d23b726442b1d
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in osuny.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rubocop", "~> 1.21"
data/Gemfile.lock ADDED
@@ -0,0 +1,55 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ osuny_api (0.2.0)
5
+ httparty
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ base64 (0.1.1)
12
+ httparty (0.21.0)
13
+ mini_mime (>= 1.0.0)
14
+ multi_xml (>= 0.5.2)
15
+ json (2.6.3)
16
+ language_server-protocol (3.17.0.3)
17
+ mini_mime (1.1.5)
18
+ multi_xml (0.6.0)
19
+ parallel (1.23.0)
20
+ parser (3.2.2.3)
21
+ ast (~> 2.4.1)
22
+ racc
23
+ racc (1.7.1)
24
+ rainbow (3.1.1)
25
+ rake (13.0.6)
26
+ regexp_parser (2.8.1)
27
+ rexml (3.2.6)
28
+ rubocop (1.56.3)
29
+ base64 (~> 0.1.1)
30
+ json (~> 2.3)
31
+ language_server-protocol (>= 3.17.0)
32
+ parallel (~> 1.10)
33
+ parser (>= 3.2.2.3)
34
+ rainbow (>= 2.2.2, < 4.0)
35
+ regexp_parser (>= 1.8, < 3.0)
36
+ rexml (>= 3.2.5, < 4.0)
37
+ rubocop-ast (>= 1.28.1, < 2.0)
38
+ ruby-progressbar (~> 1.7)
39
+ unicode-display_width (>= 2.4.0, < 3.0)
40
+ rubocop-ast (1.29.0)
41
+ parser (>= 3.2.1.0)
42
+ ruby-progressbar (1.13.0)
43
+ unicode-display_width (2.4.2)
44
+
45
+ PLATFORMS
46
+ arm64-darwin-22
47
+ x86_64-darwin-22
48
+
49
+ DEPENDENCIES
50
+ osuny_api!
51
+ rake (~> 13.0)
52
+ rubocop (~> 1.21)
53
+
54
+ BUNDLED WITH
55
+ 2.4.6
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Arnaud Levy
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,30 @@
1
+ # Osuny API
2
+
3
+ ## Installation
4
+
5
+ Install the gem and add to the application's Gemfile by executing:
6
+
7
+ $ bundle add osuny_api
8
+
9
+ If bundler is not being used to manage dependencies, install the gem by executing:
10
+
11
+ $ gem install osuny_api
12
+
13
+ ## Usage
14
+
15
+ ```
16
+ osuny = OsunyApi.new instance: 'https://instance.osuny.org',
17
+ token: 'real_token'
18
+
19
+ migration_identifier = "identifiant-unique"
20
+ post = {
21
+ title: 'Titre importé'
22
+ }
23
+ osuny.communication
24
+ .website('real_website_id')
25
+ .post
26
+ .import(migration_identifier, post)
27
+ ```
28
+ ## License
29
+
30
+ 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,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: :rubocop
@@ -0,0 +1,39 @@
1
+ require 'httparty'
2
+
3
+ class OsunyApi::Client
4
+ attr_reader :instance, :token
5
+
6
+ LOG_GREEN = 32
7
+ LOG_RED = 31
8
+
9
+ def initialize(options = {})
10
+ @instance = options[:instance]
11
+ @token = options[:token]
12
+ end
13
+
14
+ def communication
15
+ @communication ||= OsunyApi::Communication.new(
16
+ client: self,
17
+ parent: OsunyApi::Resource.new(client: self)
18
+ )
19
+ end
20
+
21
+ def post(url, body = {})
22
+ log "[POST] #{url}", LOG_GREEN
23
+ response = HTTParty.post url,
24
+ body: body,
25
+ headers: headers
26
+ log response.code
27
+ end
28
+
29
+ protected
30
+
31
+ def headers
32
+ { "X-Osuny-Token": token }
33
+ end
34
+
35
+ def log(string, color = nil)
36
+ puts color.nil? ? string
37
+ : "\e[#{color}m#{string}\e[0m"
38
+ end
39
+ end
@@ -0,0 +1,13 @@
1
+ class OsunyApi::Communication::Website::Post < OsunyApi::Resource
2
+
3
+ def path
4
+ 'posts/'
5
+ end
6
+
7
+ def import(migration_identifier, data)
8
+ client.post "#{full_path}import", {
9
+ migration_identifier: migration_identifier,
10
+ post: data
11
+ }
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ class OsunyApi::Communication::Website < OsunyApi::Resource
2
+ attr_accessor :id
3
+
4
+ def path
5
+ id.nil? ? "websites/"
6
+ : "websites/#{id}/"
7
+ end
8
+
9
+ def post
10
+ @post ||= Post.new(client: client, parent: self)
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ class OsunyApi::Communication < OsunyApi::Resource
2
+ def path
3
+ 'communication/'
4
+ end
5
+
6
+ def website(id = nil)
7
+ @website ||= Website.new(client: client, parent: self)
8
+ @website.id = id
9
+ @website
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ class OsunyApi::Error < StandardError
2
+ end
@@ -0,0 +1,18 @@
1
+ class OsunyApi::Resource
2
+ attr_reader :parent, :client
3
+
4
+ def initialize(options = {})
5
+ @client = OsunyApi::Client.new options if options.has_key? :token
6
+ @parent = options[:parent] if options.has_key? :parent
7
+ @client = options[:client] if options.has_key? :client
8
+ end
9
+
10
+ def path
11
+ "#{client.instance}/api/osuny/"
12
+ end
13
+
14
+ def full_path
15
+ parent.nil? ? "#{path}"
16
+ : "#{parent.full_path}#{path}"
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OsunyApi
4
+ VERSION = "0.2.0"
5
+ end
data/lib/osuny_api.rb ADDED
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "osuny_api/client"
4
+ require_relative "osuny_api/error"
5
+ require_relative "osuny_api/version"
6
+
7
+ require_relative "osuny_api/resource"
8
+ require_relative "osuny_api/communication"
9
+ require_relative "osuny_api/communication/website"
10
+ require_relative "osuny_api/communication/website/post"
11
+
12
+ module OsunyApi
13
+ class << self
14
+ def new(options = {})
15
+ OsunyApi::Client.new options
16
+ end
17
+ end
18
+ end
data/osuny_api.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/osuny_api/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "osuny_api"
7
+ spec.version = OsunyApi::VERSION
8
+ spec.authors = ["Arnaud Levy", "Sébastien Gaya"]
9
+ spec.email = ["contact@arnaudlevy.com", "sebastien.gaya@gmail.com"]
10
+
11
+ spec.summary = "Gem Ruby pour l'API Osuny"
12
+ spec.homepage = "https://www.github.com/noesya/osuny_api"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = ">= 2.6.0"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://www.github.com/noesya/osuny_api"
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(__dir__) do
22
+ `git ls-files -z`.split("\x0").reject do |f|
23
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
24
+ end
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency "httparty"
31
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: osuny_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Arnaud Levy
8
+ - Sébastien Gaya
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2023-09-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ description:
29
+ email:
30
+ - contact@arnaudlevy.com
31
+ - sebastien.gaya@gmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - Gemfile
37
+ - Gemfile.lock
38
+ - LICENSE.txt
39
+ - README.md
40
+ - Rakefile
41
+ - lib/osuny_api.rb
42
+ - lib/osuny_api/client.rb
43
+ - lib/osuny_api/communication.rb
44
+ - lib/osuny_api/communication/website.rb
45
+ - lib/osuny_api/communication/website/post.rb
46
+ - lib/osuny_api/error.rb
47
+ - lib/osuny_api/resource.rb
48
+ - lib/osuny_api/version.rb
49
+ - osuny_api.gemspec
50
+ homepage: https://www.github.com/noesya/osuny_api
51
+ licenses:
52
+ - MIT
53
+ metadata:
54
+ homepage_uri: https://www.github.com/noesya/osuny_api
55
+ source_code_uri: https://www.github.com/noesya/osuny_api
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 2.6.0
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubygems_version: 3.4.13
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: Gem Ruby pour l'API Osuny
75
+ test_files: []