Class: Origen::Client

Inherits:
Object show all
Includes:
HTTParty
Defined in:
lib/origen/client.rb

Overview

Client for communicating with the Origen server

Constant Summary collapse

USE_DEV_SERVER =
false
DEV_PORT =
3000

Instance Method Summary collapse

Instance Method Details

#get(path, options = {}) ⇒ Object



19
20
21
# File 'lib/origen/client.rb', line 19

def get(path, options = {})
  self.class.get("#{url}/#{path}", options)
end

#latest_developmentObject

Returns the latest developmen Origen version



83
84
85
# File 'lib/origen/client.rb', line 83

def latest_development
  Origen::VersionString.new(origen[:latest_version_dev])
end

#latest_productionObject

Returns the latest production Origen version



78
79
80
# File 'lib/origen/client.rb', line 78

def latest_production
  Origen::VersionString.new(origen[:latest_version_prod])
end

#origenObject Also known as: origen_core

Returns a data packet for Origen core



56
57
58
59
60
61
# File 'lib/origen/client.rb', line 56

def origen
  @origen ||= begin
    response = get('plugins/origen_core')
    JSON.parse(response.body, symbolize_names: true)[:plugin]
  end
end

#plugin(name) ⇒ Object



50
51
52
53
# File 'lib/origen/client.rb', line 50

def plugin(name)
  response = get("plugins/#{name}")
  JSON.parse(response.body, symbolize_names: true)[:plugin]
end

#pluginsObject

Returns an array of data packets for all plugins



44
45
46
47
48
# File 'lib/origen/client.rb', line 44

def plugins
  return @plugins if @plugins
  response = get('plugins')
  @plugins = JSON.parse(response.body, symbolize_names: true)[:plugins]
end

#portObject



27
28
29
# File 'lib/origen/client.rb', line 27

def port
  USE_DEV_SERVER ? DEV_PORT : 80
end

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



14
15
16
17
# File 'lib/origen/client.rb', line 14

def post(path, options = {})
  options[:port] = port
  self.class.post("#{url}/#{path}", options)
end

#record_invocation(command) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/origen/client.rb', line 31

def record_invocation(command)
  data = {
    user:           Origen.current_user.core_id,
    application:    Origen.app.config.initials,
    app_version:    Origen.app.version,
    origen_version: Origen.version,
    command:        command,
    platform:       Origen.running_on_windows? ? 'windows' : 'linux'
  }
  post('record_invocation', body: data)
end

#release!Object

This will be called by the Origen release process to post the latest app version information to the server



66
67
68
69
70
71
72
73
74
75
# File 'lib/origen/client.rb', line 66

def release!
  version = Origen.app.version
  body = { version: version.to_s }
  if version.production?
    body[:type] = :production
  else
    body[:type] = :development
  end
  post("plugins/#{Origen.app.name}/release", body: body)
end

#urlObject



23
24
25
# File 'lib/origen/client.rb', line 23

def url
  'http://hub.origen-sdk.org/api'
end