Class: DevStructure::API::Blueprints

Inherits:
Object
  • Object
show all
Includes:
DevStructure
Defined in:
lib/devstructure/api.rb

Instance Method Summary collapse

Constructor Details

#initialize(api, username = nil) ⇒ Blueprints

Returns a new instance of Blueprints.



54
55
56
57
# File 'lib/devstructure/api.rb', line 54

def initialize(api, username=nil)
  @api = api
  @username = username
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/devstructure/api.rb', line 59

def method_missing(symbol, *args)
  if @username
    get symbol.to_s
  else
    @username = symbol.to_s
    self
  end
end

Instance Method Details

#delete(name, options = {}) ⇒ Object



93
94
95
96
97
98
# File 'lib/devstructure/api.rb', line 93

def delete(name, options={})
  @api.start unless @api.started?
  response = @api.delete(@api.path("blueprints", @username, name),
    @api.headers)
  response
end

#get(name, token = nil) ⇒ Object



77
78
79
80
81
82
83
84
# File 'lib/devstructure/api.rb', line 77

def get(name, token=nil)
  @api.start unless @api.started?
  response = @api.get(@api.path("blueprints", @username, name, token),
    @api.headers)
  return response unless Net::HTTPOK == response.class
  hash = JSON.parse(response.body)
  Blueprint.new(hash["name"], hash)
end

#listObject



68
69
70
71
72
73
74
75
# File 'lib/devstructure/api.rb', line 68

def list
  @api.start unless @api.started?
  response = @api.get(@api.path("blueprints", @username), @api.headers)
  return response unless Net::HTTPOK == response.class
  JSON.parse(response.body).collect do |hash|
    Blueprint.new(hash["name"], hash)
  end
end

#post(name, options = {}) ⇒ Object



86
87
88
89
90
91
# File 'lib/devstructure/api.rb', line 86

def post(name, options={})
  @api.start unless @api.started?
  response = @api.post(@api.path("blueprints", @username, name),
    JSON.generate(options), @api.headers)
  response
end