Class: Apiary::Command::Archive
- Inherits:
-
Object
- Object
- Apiary::Command::Archive
- Defined in:
- lib/apiary/command/archive.rb
Overview
Retrieve blueprint from apiary
Instance Method Summary collapse
- #apilist_from_apiary ⇒ Object
- #execute ⇒ Object
-
#initialize(opts) ⇒ Archive
constructor
A new instance of Archive.
- #query_apiary ⇒ Object
Constructor Details
#initialize(opts) ⇒ Archive
Returns a new instance of Archive.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/apiary/command/archive.rb', line 11 def initialize(opts) = OpenStruct.new(opts) .api_host ||= 'api.apiary.io' .api_key ||= ENV['APIARY_API_KEY'] .proxy ||= ENV['http_proxy'] .headers ||= { accept: 'application/json', content_type: 'application/json', authorization: "Bearer #{@options.api_key}", user_agent: Apiary.user_agent } end |
Instance Method Details
#apilist_from_apiary ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/apiary/command/archive.rb', line 32 def apilist_from_apiary unless .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| if api['apiIsTeam'] == true && .exclude_team_projects == true puts "#{api['apiSubdomain']}... Team API skipping" next end puts api['apiSubdomain'] = OpenStruct.new .api_host ||= 'api.apiary.io' .api_name ||= api['apiSubdomain'] .api_key ||= ENV['APIARY_API_KEY'] .proxy ||= ENV['http_proxy'] .output ||= api['apiSubdomain'] + '.apib' .headers ||= { accept: 'text/html', content_type: 'text/plain', authentication: "Token #{@options.api_key}", user_agent: Apiary.user_agent } cmd = Apiary::Command::Fetch.new() cmd.execute end end |
#execute ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/apiary/command/archive.rb', line 24 def execute response = apilist_from_apiary return unless response.instance_of? String puts response end |
#query_apiary ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/apiary/command/archive.rb', line 63 def query_apiary url = "https://#{@options.api_host}/me/apis" RestClient.proxy = .proxy begin response = RestClient.get url, .headers rescue RestClient::Exception => e abort "Apiary service responded with an error: #{e.message}" end JSON.parse response.body end |