Class: Origen::Client

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

Overview

Client for communicating with the Origen server

Constant Summary collapse

USE_DEV_SERVER =

include HTTParty

false
DEV_PORT =
3000

Instance Method Summary collapse

Instance Method Details

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



21
22
23
# File 'lib/origen/client.rb', line 21

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

#latest_developmentObject

Returns the latest developmen Origen version



95
96
97
# File 'lib/origen/client.rb', line 95

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

#latest_productionObject

Returns the latest production Origen version



90
91
92
# File 'lib/origen/client.rb', line 90

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

#origenObject Also known as: origen_core

Returns a data packet for Origen core



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

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

#plugin(name) ⇒ Object



62
63
64
65
# File 'lib/origen/client.rb', line 62

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



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

def plugins
  return @plugins if @plugins

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

#portObject



33
34
35
# File 'lib/origen/client.rb', line 33

def port
  USE_DEV_SERVER ? DEV_PORT : 80
end

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



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

def post(path, options = {})
  options[:port] = port
  invocation_url = URI.parse("#{url}/#{path}")
  http = Net::HTTP.new(invocation_url.host, invocation_url.port)
  http.post(invocation_url, JSON.dump(options[:body]), 'Content-type' => 'application/vnd.api+json', 'Accept' => 'text/json, application/vnd.api+json')
end

#record_invocation(command) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/origen/client.rb', line 37

def record_invocation(command)
  content = {
    data: {
      type:       'applications',
      attributes: {
        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('applications', body: content)
end

#release!Object

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



78
79
80
81
82
83
84
85
86
87
# File 'lib/origen/client.rb', line 78

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



25
26
27
28
29
30
31
# File 'lib/origen/client.rb', line 25

def url
  if Origen.site_config.invocation_url.nil?
    'http://localhost:3000'
  else
    Origen.site_config.invocation_url
  end
end