Module: PagiiiApi

Defined in:
lib/pagiii-api.rb,
lib/pagiii_api/base.rb,
lib/pagiii_api/page.rb,
lib/pagiii_api/site.rb,
lib/pagiii_api/asset.rb,
lib/pagiii_api/photo.rb,
lib/pagiii_api/theme.rb,
lib/pagiii_api/version.rb,
lib/pagiii_api/metafield.rb

Defined Under Namespace

Classes: Asset, Base, Error, Metafield, Page, Photo, Site, Theme

Constant Summary collapse

VERSION =
'0.1.3'
@@access_token =
nil

Class Method Summary collapse

Class Method Details

.access_tokenObject



19
20
21
# File 'lib/pagiii-api.rb', line 19

def self.access_token
  @@access_token
end

.access_token=(token) ⇒ Object



15
16
17
# File 'lib/pagiii-api.rb', line 15

def self.access_token=(token)
  @@access_token = token
end

.build_response(response) ⇒ Object



50
51
52
53
54
55
# File 'lib/pagiii-api.rb', line 50

def self.build_response(response)
  {
    'status' => response.status,
    'response' => JSON.parse(response.body)
  }
end

.create_connectionObject



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/pagiii-api.rb', line 23

def self.create_connection
  default_header = {
    'Content-Type' => 'application/json',
    'Authorization' => "Bearer #{access_token}"
  }
  conn = Faraday.new(
    url: pagi_url,
    headers: default_header,
  )do |faraday|
    faraday.ssl.verify = false
  end
  conn
end

.create_upload_connectionObject



37
38
39
40
41
42
43
44
# File 'lib/pagiii-api.rb', line 37

def self.create_upload_connection
  Faraday.new(pagi_url) do |f|
    f.request :multipart
    f.request :url_encoded
    f.request :authorization, 'Bearer', access_token
    f.adapter :net_http
  end
end

.pagi_urlObject



46
47
48
# File 'lib/pagiii-api.rb', line 46

def self.pagi_url
  ENV.fetch('PAGIII_ROOT_API', 'https://pagiii.com')
end