Class: Rpdoc::PostmanCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/rpdoc/postman_collection.rb

Instance Method Summary collapse

Constructor Details

#initializePostmanCollection

Returns a new instance of PostmanCollection.



8
9
10
11
12
13
# File 'lib/rpdoc/postman_collection.rb', line 8

def initialize
  @configuration = Rpdoc.configuration
  @requester = JsonRequester.new(@configuration.postman_host)

  @data = generated_collection_data
end

Instance Method Details

#push_and_createObject



15
16
17
18
19
20
21
# File 'lib/rpdoc/postman_collection.rb', line 15

def push_and_create
  path = "#{@configuration.postman_collection_path}?workspace=#{@configuration.collection_workspace}"
  headers = {
    'X-Api-Key': @configuration.postman_apikey
  }
  @requester.http_send(:post, path, @data, headers)
end

#push_and_updateObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rpdoc/postman_collection.rb', line 23

def push_and_update
  path = "#{@configuration.postman_collection_path}/#{@configuration.collection_uid}"
  headers = {
    'X-Api-Key': @configuration.postman_apikey
  }
  remote_collection_data = @requester.http_send(:get, path, {}, headers)
  remote_collection_data = remote_collection_data['status'] == 200 ? remote_collection_data.deep_symbolize_keys.slice(:collection) : nil
  
  merged_by(remote_collection_data)
  @requester.http_send(:put, path, remote_collection_data, headers)
end

#saveObject



35
36
37
38
39
# File 'lib/rpdoc/postman_collection.rb', line 35

def save
  File.open("#{@configuration.rpdoc_root}/#{@configuration.rpdoc_collection_filename}", 'w+') do |f|
    f.write(JSON.pretty_generate(@data))
  end
end