pagiii-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: f9e58ed4ace1cc7cac4139aebe013af9976fac44cc2ee30af85e3f7335124b62
4
- data.tar.gz: a6c10f28b1c0a829c64a0f15800244c816927605770a18e7e10a666edb8d83a1
3
+ metadata.gz: 50930cfccc9b20f744cd67882b13f9405ae6a287622a12bba2dd0b817be6d432
4
+ data.tar.gz: 10a62e51fd12ae93fd06661c8c84445571d880a64791c6701ecd984a8b4436ac
5
5
  SHA512:
6
- metadata.gz: aafe251f6cd7eac64623ab01f165612a385c6e8bc3bdf2828fa7bed64f77ca62d24454504acd030286a301f148d84c6dbc5479c61c7f32b10c6eb2dd32521204
7
- data.tar.gz: 0b7744c1b5bf66d8e954308dcd97cc81cb7968a35fa4e9abfe8886d1eabde9b23cc070e7690287348d7e9c2eb6de589d53a91d6ce94ae2b36fd4a072a838ca53
6
+ metadata.gz: afdd4db21e2dafc6e9b587c864a4e618cd8032051c2a9bb630ac182efbf7110ec73d28fd5b1da79fba0ee37a4579e2a5d60c18bb2bfa451b6f83e62dcc18497c
7
+ data.tar.gz: 28a8bd1c41bd69985236da359352b240cf20dc53c08945647a3cc4a71124d6bda923439579d9a038234efdbc948224d69fad40d25c1133e2fd0f40f00643eb5d
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "pagiii"
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
data/lib/pagiii-api.rb ADDED
@@ -0,0 +1,56 @@
1
+ require 'pagiii_api/version'
2
+ require 'pagiii_api/base'
3
+ require 'pagiii_api/page'
4
+ require 'pagiii_api/metafield'
5
+ require 'pagiii_api/photo'
6
+ require 'pagiii_api/site'
7
+ require 'pagiii_api/theme'
8
+ require 'pagiii_api/asset'
9
+
10
+ module PagiiiApi
11
+ class Error < StandardError; end
12
+
13
+ @@access_token = nil
14
+
15
+ def self.access_token=(token)
16
+ @@access_token = token
17
+ end
18
+
19
+ def self.access_token
20
+ @@access_token
21
+ end
22
+
23
+ def self.create_connection
24
+ default_header = {
25
+ 'Content-Type' => 'application/json',
26
+ 'Authorization' => "Bearer #{access_token}"
27
+ }
28
+ conn = Faraday.new(
29
+ url: pagi_url,
30
+ headers: default_header,
31
+ )do |faraday|
32
+ faraday.ssl.verify = false
33
+ end
34
+ conn
35
+ end
36
+
37
+ def self.create_upload_connection
38
+ Faraday.new(pagi_url) do |f|
39
+ f.request :multipart
40
+ f.request :url_encoded
41
+ f.request :authorization, 'Bearer', access_token
42
+ f.adapter :net_http
43
+ end
44
+ end
45
+
46
+ def self.pagi_url
47
+ ENV.fetch('PAGIII_ROOT_API', 'https://pagiii.com')
48
+ end
49
+
50
+ def self.build_response(response)
51
+ {
52
+ 'status' => response.status,
53
+ 'response' => JSON.parse(response.body)
54
+ }
55
+ end
56
+ end
@@ -0,0 +1,34 @@
1
+ module PagiiiApi
2
+ class Asset
3
+ class << self
4
+ def create(theme_id:, asset_key:, content:)
5
+ conn = Pagiii.create_connection
6
+
7
+ ext = File.extname(asset_key)
8
+ if [".png", ".jpg", ".jpeg", ".gif"].include?(ext)
9
+ data = Base64.encode64(content)
10
+ else
11
+ data = content
12
+ end
13
+
14
+ response = conn.post("/api/v1/admin/themes/#{theme_id}/assets") do |req|
15
+ req.body = {
16
+ key: asset_key,
17
+ data:
18
+ }.to_json
19
+ end
20
+ Pagiii.build_response(response)
21
+ end
22
+
23
+ def list(page = 1)
24
+ conn = Pagiii.create_connection
25
+
26
+ response = conn.get("/api/v1/admin/themes/#{theme_id}/assets") do |req|
27
+ req.params['page'] = page
28
+ end
29
+
30
+ Pagiii.build_response(response)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,4 @@
1
+ module PagiiiApi
2
+ class Base
3
+ end
4
+ end
@@ -0,0 +1,17 @@
1
+ module PagiiiApi
2
+ class Metafield < PagiiiApi::Base
3
+ class << self
4
+ def update(page_id:, options:)
5
+ conn = Pagiii.create_connection
6
+
7
+ response = conn.patch("/api/v1/admin/pages/#{page_id}/metafield") do |req|
8
+ req.body = {
9
+ metafield: options
10
+ }.to_json
11
+ end
12
+
13
+ Pagiii.build_response(response)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,26 @@
1
+ module PagiiiApi
2
+ class Page
3
+ class << self
4
+ def create(options)
5
+ conn = Pagiii.create_connection
6
+
7
+ response = conn.post("/api/v1/admin/pages") do |req|
8
+ req.body = {
9
+ page: options
10
+ }.to_json
11
+ end
12
+ Pagiii.build_response(response)
13
+ end
14
+
15
+ def list(page = 1)
16
+ conn = Pagiii.create_connection
17
+
18
+ response = conn.get("/api/v1/admin/pages") do |req|
19
+ req.params['page'] = page
20
+ end
21
+
22
+ Pagiii.build_response(response)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,28 @@
1
+ module PagiiiApi
2
+ class Photo
3
+ class << self
4
+ def create(options)
5
+ conn = Pagiii.create_connection
6
+
7
+ response = conn.post("/api/v1/admin/photos") do |req|
8
+ req.body = {
9
+ photo: options
10
+ }.to_json
11
+ end
12
+ Pagiii.build_response(response)
13
+ end
14
+
15
+ def delete(photo_id:)
16
+ conn = Pagiii.create_connection
17
+ conn.post("/api/v1/admin/photos/#{photo_id}")
18
+ end
19
+
20
+ def attach(photo_id:, path:)
21
+ conn = Pagiii.create_upload_connection
22
+ payload = { image: Faraday::FilePart.new(path, 'image/jpeg') }
23
+ response = conn.post("/api/v1/admin/photos/#{photo_id}/attach", payload)
24
+ Pagiii.build_response(response)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,4 @@
1
+ module PagiiiApi
2
+ class Site
3
+ end
4
+ end
@@ -0,0 +1,36 @@
1
+ module PagiiiApi
2
+ class Theme
3
+ class << self
4
+ # Arguments: name
5
+ def create(options)
6
+ conn = Pagiii.create_connection
7
+
8
+ response = conn.post("/api/v1/admin/themes") do |req|
9
+ req.body = {
10
+ theme: options
11
+ }.to_json
12
+ end
13
+ Pagiii.build_response(response)
14
+ end
15
+
16
+ def list(page = 1)
17
+ conn = Pagiii.create_connection
18
+
19
+ response = conn.get("/api/v1/admin/themes") do |req|
20
+ req.params['page'] = page
21
+ end
22
+
23
+ Pagiii.build_response(response)
24
+ end
25
+
26
+ def set_current(theme_id)
27
+ conn = Pagiii.create_connection
28
+
29
+ response = conn.patch("/api/v1/admin/themes/#{theme_id}/set_current") do |req|
30
+ req.body = {}.to_json
31
+ end
32
+ Pagiii.build_response(response)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module PagiiiApi
2
+ VERSION = '0.1.1'
3
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagiii-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
  - Sugiarto
@@ -44,7 +44,18 @@ email:
44
44
  executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
- files: []
47
+ files:
48
+ - bin/console
49
+ - bin/setup
50
+ - lib/pagiii-api.rb
51
+ - lib/pagiii_api/asset.rb
52
+ - lib/pagiii_api/base.rb
53
+ - lib/pagiii_api/metafield.rb
54
+ - lib/pagiii_api/page.rb
55
+ - lib/pagiii_api/photo.rb
56
+ - lib/pagiii_api/site.rb
57
+ - lib/pagiii_api/theme.rb
58
+ - lib/pagiii_api/version.rb
48
59
  homepage: http://rubygems.org/gems/pagiii-api
49
60
  licenses:
50
61
  - MIT