Class: Pod::Components_api

Inherits:
Object
  • Object
show all
Includes:
Concurrent::Async
Defined in:
lib/cocoapods-vemars/services/components_api.rb

Constant Summary collapse

COMPONENTS_URL =
'https://mars-fwk.vemarsdev.com/mpaas/baseline/baseline_config'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(baseline = nil, url = COMPONENTS_URL) ⇒ Components_api

Returns a new instance of Components_api.



16
17
18
19
20
21
22
# File 'lib/cocoapods-vemars/services/components_api.rb', line 16

public def initialize(baseline=nil,url=COMPONENTS_URL)
  @baseline = baseline
  @source = ""
  @component_list = []
  @baseline_api = Baselines_api.new(url)
  @components_url = (url.blank? ? COMPONENTS_URL : url + "/baseline/baseline_config")
end

Instance Attribute Details

#baselineObject (readonly)

Returns the value of attribute baseline.



11
12
13
# File 'lib/cocoapods-vemars/services/components_api.rb', line 11

def baseline
  @baseline
end

#baseline_apiObject (readonly)

Returns the value of attribute baseline_api.



13
14
15
# File 'lib/cocoapods-vemars/services/components_api.rb', line 13

def baseline_api
  @baseline_api
end

#component_listObject (readonly)

Returns the value of attribute component_list.



12
13
14
# File 'lib/cocoapods-vemars/services/components_api.rb', line 12

def component_list
  @component_list
end

#components_urlObject (readonly)

Returns the value of attribute components_url.



14
15
16
# File 'lib/cocoapods-vemars/services/components_api.rb', line 14

def components_url
  @components_url
end

#sourceObject (readonly)

Returns the value of attribute source.



10
11
12
# File 'lib/cocoapods-vemars/services/components_api.rb', line 10

def source
  @source
end

Instance Method Details

#deserilise(response) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/cocoapods-vemars/services/components_api.rb', line 46

def deserilise(response)
  if response.ok?
    json = JSON.parse(response.body)
    error_code = json["error_no"]
    if error_code == 0
      @source = json['data']['source']
      @component_list = json['data']['iosPlugins'].map { |obj| Component.new(obj) }
    else
      puts "Error #{error_code}(#{json["error_msg"]}): #{json["err_detail"]}}"
    end
  else
    puts "fail to get components, response status: #{response.status_code}"
  end
end

#getComponents(baseline = @baseline) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/cocoapods-vemars/services/components_api.rb', line 38

public def getComponents(baseline=@baseline)
  body= "{\"baseline_version\": \"#{baseline}\", \"technology_stack\": \"iOS\"}"
  header = {"ContentType" => 'application/json'}
  response = REST.post(@components_url, body, header)
  deserilise(response)
  return component_list
end

#validate!Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cocoapods-vemars/services/components_api.rb', line 24

public def validate!
  baseline_api.await.getBaselines
  if @baseline.nil? && baseline_api.result.length() == 0
    help! "No baselines info existed, please check with server admin"
  elsif @baseline.nil? && baseline_api.result.length() > 0
    @baseline = baseline_api.result[0]
  elsif  !@baseline.nil? && baseline_api.result.length() > 0
    if !baseline_api.result.include?(@baseline)
      puts "Invalid baseline version provided!"
      help! "Invalid baseline version provided!"
    end
  end
end