This repository has been archived by the owner on Nov 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #205 from apiaryio/abtris/archive
feat: add archive command
- Loading branch information
Showing
4 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# encoding: utf-8 | ||
|
||
require 'rest-client' | ||
require 'json' | ||
|
||
require 'apiary/agent' | ||
|
||
module Apiary::Command | ||
# Retrieve blueprint from apiary | ||
class Archive | ||
def initialize(opts) | ||
@options = OpenStruct.new(opts) | ||
@options.api_host ||= 'api.apiary.io' | ||
@options.api_key ||= ENV['APIARY_API_KEY'] | ||
@options.proxy ||= ENV['http_proxy'] | ||
@options.headers ||= { | ||
accept: 'application/json', | ||
content_type: 'application/json', | ||
authorization: "Bearer #{@options.api_key}", | ||
user_agent: Apiary.user_agent | ||
} | ||
end | ||
|
||
def execute | ||
response = apilist_from_apiary | ||
|
||
return unless response.instance_of? String | ||
|
||
puts response | ||
end | ||
|
||
def apilist_from_apiary | ||
unless @options.api_key | ||
abort 'API key must be provided through environment variable APIARY_API_KEY. Please go to https://login.apiary.io/tokens to obtain it.' | ||
end | ||
|
||
response = query_apiary | ||
|
||
response['apis'].each do |api| | ||
puts api['apiSubdomain'] | ||
@options = OpenStruct.new | ||
@options.api_host ||= 'api.apiary.io' | ||
@options.api_name ||= api['apiSubdomain'] | ||
@options.api_key ||= ENV['APIARY_API_KEY'] | ||
@options.proxy ||= ENV['http_proxy'] | ||
@options.output ||= api['apiSubdomain'] + '.apib' | ||
@options.headers ||= { | ||
accept: 'text/html', | ||
content_type: 'text/plain', | ||
authentication: "Token #{@options.api_key}", | ||
user_agent: Apiary.user_agent | ||
} | ||
cmd = Apiary::Command::Fetch.new(@options) | ||
cmd.execute | ||
end | ||
end | ||
|
||
def query_apiary | ||
url = "https://#{@options.api_host}/me/apis" | ||
RestClient.proxy = @options.proxy | ||
|
||
begin | ||
response = RestClient.get url, @options.headers | ||
rescue RestClient::Exception => e | ||
abort "Apiary service responded with an error: #{e.message}" | ||
end | ||
JSON.parse response.body | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Apiary | ||
VERSION = '0.15.2'.freeze | ||
VERSION = '0.16.0'.freeze | ||
end |