Class: RestfulPress::Client

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

Constant Summary collapse

@@connection =
nil
@@debug =
false

Class Method Summary collapse

Class Method Details

.add_job(*args) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/restful_press/client.rb', line 25

def add_job(*args)
  options = extract_options!(args)
  params = Hash.new
  params[:job] = options
  
  response = post(Endpoint.jobs, params)
  HashUtils.recursively_symbolize_keys(response)
end

.debugObject



21
22
23
# File 'lib/restful_press/client.rb', line 21

def debug
  @@debug
end

.debug=(debug_flag) ⇒ Object



16
17
18
19
# File 'lib/restful_press/client.rb', line 16

def debug=(debug_flag)
  @@debug = debug_flag
  @@connection.debug = @@debug if @@connection
end

.delete(endpoint, data = nil) ⇒ Object



71
72
73
74
# File 'lib/restful_press/client.rb', line 71

def delete(endpoint, data=nil)
  raise NoConnectionEstablished  if @@connection.nil?
  @@connection.delete endpoint, data
end

.delete_job(id) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/restful_press/client.rb', line 44

def delete_job(id)
  response = delete(Endpoint.job(id))
  if response.nil?
    return true
  else
    HashUtils.recursively_symbolize_keys(response)
  end
end

.get(endpoint, data = nil) ⇒ Object



66
67
68
69
# File 'lib/restful_press/client.rb', line 66

def get(endpoint, data=nil)
  raise NoConnectionEstablished  if @@connection.nil?
  @@connection.get endpoint, data
end

.get_job(id) ⇒ Object



34
35
36
37
# File 'lib/restful_press/client.rb', line 34

def get_job(id)
  response = get(Endpoint.job(id))
  HashUtils.recursively_symbolize_keys(response)
end

.get_jobsObject



39
40
41
42
# File 'lib/restful_press/client.rb', line 39

def get_jobs
  response = get(Endpoint.jobs)
  HashUtils.recursively_symbolize_keys(response)
end

.job_complete?(id) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/restful_press/client.rb', line 62

def job_complete?(id)
  get_job(id)[:complete]
end

.job_download(id) ⇒ Object



57
58
59
60
# File 'lib/restful_press/client.rb', line 57

def job_download(id)
  response = get(Endpoint.download_job(id))
  HashUtils.recursively_symbolize_keys(response)
end

.job_url(id) ⇒ Object



53
54
55
# File 'lib/restful_press/client.rb', line 53

def job_url(id)
  Endpoint.download_job(id)
end

.post(endpoint, data = nil) ⇒ Object



76
77
78
79
# File 'lib/restful_press/client.rb', line 76

def post(endpoint, data=nil)
  raise NoConnectionEstablished  if @@connection.nil?
  @@connection.post endpoint, data
end

.put(endpoint, data = nil) ⇒ Object



81
82
83
84
# File 'lib/restful_press/client.rb', line 81

def put(endpoint, data=nil)
  raise NoConnectionEstablished  if @@connection.nil?
  @@connection.put endpoint, data
end

.set_credentials(api_key) ⇒ Object



10
11
12
13
14
# File 'lib/restful_press/client.rb', line 10

def set_credentials(api_key)
  @@connection = Connection.new(api_key)
  @@connection.debug = @@debug
  true
end