osuny_api 0.2.0 → 0.2.2

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: f1a3d2e6cd60019b441bb74ea0a77416530c7db75ecf2ec8abfb0c7628b39bde
4
- data.tar.gz: 5220e60f717e00ec7fa04fe76be021b3432578d83cf5381f94b79d779ad888c1
3
+ metadata.gz: aa384d23e319961d074a82202f346b2d6dc652f98076c6fb2a07d60b913f00af
4
+ data.tar.gz: 466248d32f23e6c958721981ef62e22dec07a56cd1024da3229a66274c150dd5
5
5
  SHA512:
6
- metadata.gz: 92967da0c264a577a5ec3c8a894042fd56df180d9657a79aa64aee964ad2007fdfb82f677f40d7780af9a231842f71d2515fef791a3e5c49d3e2353157c2c994
7
- data.tar.gz: f232a0fb21d4e152450abddfe081daf801525332c6da3a274b8b63f8cac09658a9618880c9e31785abf1c7e43195e7995375b3923b8d672bd50d23b726442b1d
6
+ metadata.gz: 90966cd42594866d5bd2d6e8857db3d9b571e8ae66a998fcc79dd896e2179e07513eb9ddfa1cbe5e8159cddd01558e9988b2dfc791eb50002b53b4c2fdc73de8
7
+ data.tar.gz: 4ee584ea2031804795ed23d7c8be4cc861b4187ddd14b8a20fa3ab87c5d7dfceaaddb9998b9250b75741690535f4acbff64576e2fa441ead0f76c88feb64d5eb
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- osuny_api (0.2.0)
4
+ osuny_api (0.2.2)
5
5
  httparty
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -13,7 +13,7 @@ If bundler is not being used to manage dependencies, install the gem by executin
13
13
  ## Usage
14
14
 
15
15
  ```
16
- osuny = OsunyApi.new instance: 'https://instance.osuny.org',
16
+ osuny = OsunyApi.new host: 'https://instance.osuny.org',
17
17
  token: 'real_token'
18
18
 
19
19
  migration_identifier = "identifiant-unique"
@@ -1,39 +1,41 @@
1
1
  require 'httparty'
2
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"
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
@@ -1,13 +1,15 @@
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(migration_identifier, data)
9
+ client.post "#{full_path}import", {
10
+ migration_identifier: migration_identifier,
11
+ post: data
12
+ }
13
+ end
12
14
  end
13
15
  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.instance}/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.0"
4
+ VERSION = "0.2.2"
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.0
4
+ version: 0.2.2
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-09-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty