Class: Megam::Scmmanager

Inherits:
Object
  • Object
show all
Defined in:
lib/megam/scmmanager.rb,
lib/megam/scmmanager/repos.rb,
lib/megam/scmmanager/errors.rb,
lib/megam/scmmanager/version.rb,
lib/megam/scmmanager/accounts.rb

Defined Under Namespace

Modules: Errors

Constant Summary collapse

HEADERS =
{
  'Accept' => 'application/json',
  'Accept-Encoding' => 'gzip',
  'User-Agent' => "megam-scmmanager/#{Megam::Scmmanager::VERSION}",
  'X-Ruby-Version' => RUBY_VERSION,
  'X-Ruby-Platform' => RUBY_PLATFORM
}
OPTIONS =
{
  :headers => {},
  :host => 'scm-manager.megam.co',
  :port => '8080',
  :nonblock => false,
  :scheme => 'http'
}
API_REST =
"/scmmanager/api/rest"
AUTH_PATH =
"/authentication/login"
VERSION =
"0.1.0"

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Scmmanager

It is assumed that every API call will NOT use an API_KEY/email.



51
52
53
# File 'lib/megam/scmmanager.rb', line 51

def initialize(options={})
  @options = OPTIONS.merge(options)
end

Instance Method Details

#get_accounts(email) ⇒ Object

GET /accounts Yet to be tested



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/megam/scmmanager/accounts.rb', line 5

def get_accounts(email)

  @options = {:path => "/users.json",
    :body => ''}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_repos(username = nil, password = nil) ⇒ Object

GET /accounts Yet to be tested



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/megam/scmmanager/repos.rb', line 5

def get_repos(username=nil, password=nil)

  @options = {:path => "/repositories",
    :body => ''}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :username => username,
    :password => password,
    :body     => @options[:body]
  )
end

#last_responseObject



46
47
48
# File 'lib/megam/scmmanager.rb', line 46

def last_response
  @last_response
end

#post_accounts(json_hash) ⇒ Object

The body content needs to be a json.



18
19
20
21
22
23
24
25
26
27
# File 'lib/megam/scmmanager/accounts.rb', line 18

def post_accounts(json_hash)
  @options = {:path => '/users.json',
  :body => json_hash[:json]}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
    )
end

#request(params, &block) ⇒ Object

Raises:

  • (ArgumentError)


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/megam/scmmanager.rb', line 55

def request(params, &block)
  start = Time.now
  puts params
  text.msg "#{text.color("START", :cyan, :bold)}"
  username =  params[:username] || ENV['MEGAM_SCMADMIN_USERNAME']
  password =  params[:password]  || ENV['MEGAM_SCMADMIN_PASSWORD']
  raise ArgumentError, "You must specify [:username, :password]" if username.nil? || password.nil?
  text.msg "#{text.color("Got username[#{username}] [*******]", :red, :bold)}"

  begin
    httpcon = connection
    httpcon.use_ssl = false
    httpcon.start do |http|
      request = Net::HTTP::Get.new(@options[:path])
      request.basic_auth username, password
      @response = http.request(request)
    end
  end
  @response
end

#textObject



42
43
44
# File 'lib/megam/scmmanager.rb', line 42

def text
  @text ||= Megam::Dumpout.new(STDOUT, STDERR, STDIN)
end