osuny_api 0.2.1 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ad40e0aa413a62e81133fb379bea4c75f21c2ed05c623675e6dcb64d7560fd8
4
- data.tar.gz: ab6da0f51fed17d500e0aad44efe3db305c44416656fb702d653aba3503f0fff
3
+ metadata.gz: 59f1b8d157560352eddae3b4b0789d18f1635e5744802a717374aba06ea0c728
4
+ data.tar.gz: e15e5b411ea1e5ba835972db77c489e4253c7871d87543c4be219eb4809c6f39
5
5
  SHA512:
6
- metadata.gz: dc3481e56415c90ac97a1489369258a0a0ed3333a454e2df42826008fd98d1eb99fd6057a870f396f9178ed648efd3f1e5503da9396603370643edfa1209410d
7
- data.tar.gz: 9b0f2d55efac94ace1c72c9ae36951de5084f178c60c94d60a40d0702a730a0262582dca0c0c446eaea746a77a8d2bdcf360c5573922c8a02d818b8b98b779a9
6
+ metadata.gz: 27ee12f06c28e81ec2896ade22829d1e844bc537cf230d75b00dfa37b8015721ef546554495eb79b96047cfc41c7059eb3aa8a6bf86cb78774d9847628ec71df
7
+ data.tar.gz: 757db895eec60bc3d015f3ef60fdafc865e07ea0f12601a31f2ee7cffea937d692429afb12f30c4d67f13e3f6458e9e178add7c9904be447f349642311db2a4b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- osuny_api (0.2.1)
4
+ osuny_api (0.2.3)
5
5
  httparty
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -16,14 +16,14 @@ If bundler is not being used to manage dependencies, install the gem by executin
16
16
  osuny = OsunyApi.new host: 'https://instance.osuny.org',
17
17
  token: 'real_token'
18
18
 
19
- migration_identifier = "identifiant-unique"
20
19
  post = {
20
+ migration_identifier: "identifiant-unique"
21
21
  title: 'Titre importé'
22
22
  }
23
23
  osuny.communication
24
24
  .website('real_website_id')
25
25
  .post
26
- .import(migration_identifier, post)
26
+ .import(post)
27
27
  ```
28
28
  ## License
29
29
 
@@ -1,39 +1,41 @@
1
1
  require 'httparty'
2
2
 
3
- class OsunyApi::Client
4
- attr_reader :host, :token
5
-
6
- LOG_GREEN = 32
7
- LOG_RED = 31
8
-
9
- def initialize(options = {})
10
- @host = options[:host]
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"
3
+ module OsunyApi
4
+ class Client
5
+ attr_reader :host, :token
6
+
7
+ LOG_GREEN = 32
8
+ LOG_RED = 31
9
+
10
+ def initialize(options = {})
11
+ @host = options[:host]
12
+ @token = options[:token]
13
+ end
14
+
15
+ def communication
16
+ @communication ||= OsunyApi::Communication.new(
17
+ client: self,
18
+ parent: OsunyApi::Resource.new(client: self)
19
+ )
20
+ end
21
+
22
+ def post(url, body = {})
23
+ log "[POST] #{url}", LOG_GREEN
24
+ response = HTTParty.post url,
25
+ body: body,
26
+ headers: headers
27
+ log response.code
28
+ end
29
+
30
+ protected
31
+
32
+ def headers
33
+ { "X-Osuny-Token": token }
34
+ end
35
+
36
+ def log(string, color = nil)
37
+ puts color.nil? ? string
38
+ : "\e[#{color}m#{string}\e[0m"
39
+ end
38
40
  end
39
- end
41
+ end
@@ -0,0 +1,12 @@
1
+ module OsunyApi
2
+ class Communication::Website::Page < Resource
3
+
4
+ def path
5
+ 'pages/'
6
+ end
7
+
8
+ def import(page)
9
+ client.post "#{full_path}import", { page: page }
10
+ end
11
+ end
12
+ end
@@ -1,13 +1,12 @@
1
- class OsunyApi::Communication::Website::Post < OsunyApi::Resource
1
+ module OsunyApi
2
+ class Communication::Website::Post < Resource
2
3
 
3
- def path
4
- 'posts/'
5
- end
4
+ def path
5
+ 'posts/'
6
+ end
6
7
 
7
- def import(migration_identifier, data)
8
- client.post "#{full_path}import", {
9
- migration_identifier: migration_identifier,
10
- post: data
11
- }
8
+ def import(post)
9
+ client.post "#{full_path}import", { post: post }
10
+ end
12
11
  end
13
12
  end
@@ -1,12 +1,14 @@
1
- class OsunyApi::Communication::Website < OsunyApi::Resource
2
- attr_accessor :id
1
+ module OsunyApi
2
+ class Communication::Website < Resource
3
+ attr_accessor :id
3
4
 
4
- def path
5
- id.nil? ? "websites/"
6
- : "websites/#{id}/"
7
- end
5
+ def path
6
+ id.nil? ? "websites/"
7
+ : "websites/#{id}/"
8
+ end
8
9
 
9
- def post
10
- @post ||= Post.new(client: client, parent: self)
10
+ def post
11
+ @post ||= Post.new(client: client, parent: self)
12
+ end
11
13
  end
12
14
  end
@@ -1,11 +1,13 @@
1
- class OsunyApi::Communication < OsunyApi::Resource
2
- def path
3
- 'communication/'
4
- end
1
+ module OsunyApi
2
+ class Communication < Resource
3
+ def path
4
+ 'communication/'
5
+ end
5
6
 
6
- def website(id = nil)
7
- @website ||= Website.new(client: client, parent: self)
8
- @website.id = id
9
- @website
7
+ def website(id = nil)
8
+ @website ||= Website.new(client: client, parent: self)
9
+ @website.id = id
10
+ @website
11
+ end
10
12
  end
11
13
  end
@@ -1,2 +1,4 @@
1
- class OsunyApi::Error < StandardError
2
- end
1
+ module OsunyApi
2
+ class Error < StandardError
3
+ end
4
+ end
@@ -1,18 +1,20 @@
1
- class OsunyApi::Resource
2
- attr_reader :parent, :client
1
+ module OsunyApi
2
+ class Resource
3
+ attr_reader :parent, :client
3
4
 
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
5
+ def initialize(options = {})
6
+ @client = OsunyApi::Client.new options if options.has_key? :token
7
+ @parent = options[:parent] if options.has_key? :parent
8
+ @client = options[:client] if options.has_key? :client
9
+ end
9
10
 
10
- def path
11
- "#{client.host}/api/osuny/"
12
- end
11
+ def path
12
+ "#{client.host}/api/osuny/"
13
+ end
13
14
 
14
- def full_path
15
- parent.nil? ? "#{path}"
16
- : "#{parent.full_path}#{path}"
15
+ def full_path
16
+ parent.nil? ? "#{path}"
17
+ : "#{parent.full_path}#{path}"
18
+ end
17
19
  end
18
20
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OsunyApi
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: osuny_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arnaud Levy
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2023-09-25 00:00:00.000000000 Z
12
+ date: 2023-10-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -42,6 +42,7 @@ files:
42
42
  - lib/osuny_api/client.rb
43
43
  - lib/osuny_api/communication.rb
44
44
  - lib/osuny_api/communication/website.rb
45
+ - lib/osuny_api/communication/website/page.rb
45
46
  - lib/osuny_api/communication/website/post.rb
46
47
  - lib/osuny_api/error.rb
47
48
  - lib/osuny_api/resource.rb
@@ -68,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
69
  - !ruby/object:Gem::Version
69
70
  version: '0'
70
71
  requirements: []
71
- rubygems_version: 3.4.13
72
+ rubygems_version: 3.4.6
72
73
  signing_key:
73
74
  specification_version: 4
74
75
  summary: Gem Ruby pour l'API Osuny