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.



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

def initialize(token=nil)
  @newimpl = true
  uri = URI.parse("https://api.devstructure.com")
  super uri.host, uri.port
  if self.use_ssl = "https" == uri.scheme
    self.verify_mode = OpenSSL::SSL::VERIFY_NONE
  end
  @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



123
124
125
# File 'lib/devstructure/api.rb', line 123

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

#headersObject



46
47
48
49
50
51
# File 'lib/devstructure/api.rb', line 46

def headers
  {
    "Authorization" => "Token token=\"#{@token}\"",
    "Host" => "api.devstructure.com",
  }
end

#path(*args) ⇒ Object



41
42
43
44
# File 'lib/devstructure/api.rb', line 41

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