cucumber-calliope_importer 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cf46107d9aa7462854d3e784d9114d2535d503da
4
- data.tar.gz: 3400f7385aedcdf67e376e81ca4e9ee0279e9670
3
+ metadata.gz: 9f8e1d46a39a368d10d2faf0e9c5c493a87cece1
4
+ data.tar.gz: e67197eb5714d0647eccc6ab8aefce7c9f3fce29
5
5
  SHA512:
6
- metadata.gz: a7e9b689fe20f8b9d0835e83fb7d6ec6dc86e4657a7159cc742b1a611a22e608c94d6dc13f52c91d68558f4bc6759f498453a16b554625e7bbf6e342f4b3ed25
7
- data.tar.gz: 5ffd81a6eb1a360964ae34bdb740dbc94bc2e78accddd5797dbc1d5c71d657a2bbd521f2c38be3cd42024709e9879b003c582e1eae8d4f7013f0078a6ff256ab
6
+ metadata.gz: 15b25fcf2f80e5a894dcd859233e7d78c9b2d0974de6bcad005185ee41a522312d14fa7d667da1cbb41cd7a0384ea26f9974cd7f7d6048eeceb654081300307e
7
+ data.tar.gz: 8641d4966cbdffa336e014738ed595487eef89120a079ffa018afa953562ee5e79b264b982c64f535d22e49e82d40ad05bb4c9955bfdbd6a9c364c1ec8b008ec
@@ -6,11 +6,21 @@ module Cucumber
6
6
  def initialize(config)
7
7
  super
8
8
  if ENV['API_KEY'].nil? || ENV['PROFILE_ID'].nil?
9
- print "\033[31m" # Sets console colors to red
10
- print "Error: API Key and/or Profile ID were not set. Please provide them in your cucumber call or profile like this API_KEY='API Key Here' PROFILE_ID='Profile ID Here'"
11
- print "\033[0m" # Resets console colors
9
+ error = "API Key and/or Profile ID were not set. Please provide them in your cucumber call or profile like this API_KEY='API Key Here' PROFILE_ID='Profile ID Here'"
10
+ print_error(error)
12
11
  exit
13
12
  end
13
+ #Set calliope data
14
+ @calliope_config = {
15
+ 'api_key' => ENV['API_KEY'],
16
+ 'profile_id' => ENV['PROFILE_ID']
17
+ }
18
+ if ENV['API_URL']
19
+ @calliope_config['url'] = ENV['API_URL']
20
+ else
21
+ @calliope_config['url'] = 'https://app.calliope/pro'
22
+ end
23
+ check_profile_permission
14
24
  end
15
25
 
16
26
  def on_finished_testing(event)
@@ -20,42 +30,62 @@ module Cucumber
20
30
  end
21
31
 
22
32
  def upload_to_api(results)
23
- # Set data for api_call
33
+ # Get metadata from test run
24
34
  metadata = JSON.parse(File.read('./storage/metadata.json'))
25
- calliope_config = {
26
- 'api_key' => ENV['API_KEY'],
27
- 'profile_id' => ENV['PROFILE_ID'],
28
- 'browser' => metadata['browser']['name'],
29
- 'os' => metadata['browser']['platform']
30
- }
35
+ @calliope_config['browser'] = metadata['browser']['name']
36
+ @calliope_config['os'] = metadata['browser']['platform']
31
37
  # Set url
32
- if ENV['API_URL']
33
- calliope_config['url'] = ENV['API_URL']
34
- else
35
- calliope_config['url'] = 'https://app.calliope/pro'
36
- end
37
- api_call(results, calliope_config)
38
+ api_call(results)
38
39
  end
39
40
 
40
- def api_call(results, calliope_config)
41
+ def api_call(results)
41
42
  # Make API call
42
- url = "#{calliope_config['url']}/api/v2/profile/#{calliope_config['profile_id']}/testresult?browser=#{calliope_config['browser']}&os=#{calliope_config['os']}"
43
+ url = "#{@calliope_config['url']}/api/v2/profile/#{@calliope_config['profile_id']}/testresult?browser=#{@calliope_config['browser']}&os=#{@calliope_config['os']}"
43
44
  url = URI.parse(url)
44
45
  http = Net::HTTP.new(url.host, url.port)
45
46
  # Enable ssl when necessary
46
- if calliope_config['url'].include? 'https://'
47
+ if @calliope_config['url'].include? 'https://'
47
48
  http.use_ssl = true
48
49
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
49
50
  end
50
51
  header = {
51
52
  'content-type' => 'application/json',
52
- 'x-api-key' => calliope_config['api_key']
53
+ 'x-api-key' => @calliope_config['api_key']
53
54
  }
54
55
  request = Net::HTTP::Post.new(url, header)
55
56
  request.body = results
56
57
  response = http.request(request)
57
58
  print "\nAPI response: #{response.body} \n"
58
59
  end
60
+
61
+ def check_profile_permission
62
+ url = "#{@calliope_config['url']}/api/v2/profile/#{@calliope_config['profile_id']}"
63
+ url = URI.parse(url)
64
+ http = Net::HTTP.new(url.host, url.port)
65
+ # Enable ssl when necessary
66
+ if @calliope_config['url'].include? 'https://'
67
+ http.use_ssl = true
68
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
69
+ end
70
+ header = {
71
+ 'content-type' => 'application/json',
72
+ 'x-api-key' => @calliope_config['api_key']
73
+ }
74
+ request = Net::HTTP::Get.new(url, header)
75
+ response = http.request(request)
76
+
77
+ if response.code != '200'
78
+ error = 'Not authorized for this calliope profile, exiting...'
79
+ print_error(error)
80
+ exit
81
+ end
82
+ end
83
+
84
+ def print_error(message)
85
+ print "\033[31m" # Sets console colors to red
86
+ print "Error: #{message}"
87
+ print "\033[0m" # Resets console colors
88
+ end
59
89
  end
60
90
  end
61
91
  end
@@ -1,5 +1,5 @@
1
1
  module Cucumber
2
2
  module CalliopeImporter
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cucumber-calliope_importer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maurice Wijnia
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-13 00:00:00.000000000 Z
11
+ date: 2017-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler