Class: RailsDocks::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/railsdocks/client.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

DEFAULT_API_URL =
"https://api.railsdocks.com"

Instance Method Summary collapse

Constructor Details

#initialize(base_url: ENV.fetch( "RAILSDOCKS_API_URL", DEFAULT_API_URL )) ⇒ Client

Returns a new instance of Client.



14
15
16
17
18
19
20
21
# File 'lib/railsdocks/client.rb', line 14

def initialize(
  base_url: ENV.fetch(
    "RAILSDOCKS_API_URL",
    DEFAULT_API_URL
  )
)
  @base_url = base_url
end

Instance Method Details

#add_domain(hostname:, app:, token:) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/railsdocks/client.rb', line 93

def add_domain(
  hostname:,
  app:,
  token:
)
  post(
    "/api/v1/domains",
    {
      hostname: hostname,
      app: app
    },
    token: token
  )
end

#apps(token:) ⇒ Object



60
61
62
63
64
65
# File 'lib/railsdocks/client.rb', line 60

def apps(token:)
  get(
    "/api/v1/apps",
    token: token
  )
end

#create_app(name:, token:, no_db: false) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/railsdocks/client.rb', line 33

def create_app(
  name:,
  token:,
  no_db: false
)
  post(
    "/api/v1/apps",
    {
      name: name,
      no_db: no_db
    },
    token: token
  )
end

#database_command(slug:, operation:, token:) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/railsdocks/client.rb', line 48

def database_command(
  slug:,
  operation:,
  token:
)
  post(
    "/api/v1/apps/#{slug}/db/#{operation}",
    {},
    token: token
  )
end

#destroy_app(slug:, confirm:, token:) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/railsdocks/client.rb', line 67

def destroy_app(
  slug:,
  confirm:,
  token:
)
  encoded_slug =
    URI.encode_www_form_component(
      slug
    )

  delete(
    "/api/v1/apps/#{encoded_slug}",
    {
      confirm: confirm
    },
    token: token
  )
end

#domains(token:) ⇒ Object



86
87
88
89
90
91
# File 'lib/railsdocks/client.rb', line 86

def domains(token:)
  get(
    "/api/v1/domains",
    token: token
  )
end

#login(email:, password:) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/railsdocks/client.rb', line 23

def (email:, password:)
  post(
    "/api/v1/login",
    {
      email: email,
      password: password
    }
  )
end

#remove_domain(hostname:, token:) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/railsdocks/client.rb', line 108

def remove_domain(
  hostname:,
  token:
)
  delete(
    "/api/v1/domains",
    {
      hostname: hostname
    },
    token: token
  )
end