Class: DevStructure::API

Inherits:
Net::HTTP
  • Object
show all
Defined in:
lib/devstructure/api.rb

Defined Under Namespace

Classes: Blueprints

Instance Method Summary collapse

Constructor Details

#initialize(token = nil) ⇒ API

Returns a new instance of API.



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

def initialize(token=nil)
  @newimpl = true
  uri = URI.parse("https://devstructure.com")
  super uri.host, uri.port
  self.use_ssl = "https" == uri.scheme
  @token = if token
    token
  else
    "#{
      File.read("/etc/token").chomp
    }#{
      File.read(File.expand_path("~/.token")).chomp
    }"
  end
end

Instance Method Details

#blueprints(username = nil) ⇒ Object



102
103
104
# File 'lib/devstructure/api.rb', line 102

def blueprints(username=nil)
  Blueprints.new(self, username)
end

#headersObject



43
44
45
46
47
48
49
# File 'lib/devstructure/api.rb', line 43

def headers
  {
    "Authorization" => "Token token=\"#{@token}\"",
    "Content-Type" => "application/json",
    "Host" => "devstructure.com",
  }
end

#path(*args) ⇒ Object



38
39
40
41
# File 'lib/devstructure/api.rb', line 38

def path(*args)
  args.reject! { |arg| arg.nil? }
  "/#{args.join("/")}.json"
end