Skip to content

Commit

Permalink
Merge pull request apiaryio#72 from apiaryio/abtris/read-bom
Browse files Browse the repository at this point in the history
Add reading apiary file with BOM
  • Loading branch information
abtris committed Mar 5, 2015
2 parents 0a48ba2 + 8842dbf commit d45ec0d
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 3 deletions.
48 changes: 48 additions & 0 deletions features/fixtures/apiary_with_bom.apib
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
FORMAT: 1A

# Apiary Client Test - DON'T CHANGE DOCUMENT!

This document is used for testing apiary-client

# Group Notes
Notes related resources of the **Notes API**

## Notes Collection [/notes
### List all Notes [GET]
+ Response 200 (application/json)

[{
"id": 1, "title": "Jogging in park"
}, {
"id": 2, "title": "Pick-up posters from post-office"
}]

### Create a Note [POST

+ Request

sflmvs;mv;dsm{ "title": "Buy cheese and bread for breakfast." }

+ Response 201 (application/json)

{ "id": 3, "title": "Buy cheese and bread for breakfast." }

## Note [/notes/{id}]
A single Note object with all its details

+ Parameters
+ id (required, number, `1`) ... Numeric `id` of the Note to perform action with. Has example value.

### Retrieve a Note [GET]
+ Response 200 (application/json)

+ Header

X-My-Header: The Value

+ Body

{ "id": 2, "title": "Pick-up posters from post-office" }

### Remove a Note [DELETE]
+ Response 204
7 changes: 6 additions & 1 deletion lib/apiary/command/publish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ def validate_apib_file(apib_file)
common.validate_apib_file(apib_file)
end

def get_apib_file(apib_file)
common = Apiary::Common.new
common.get_apib_file(apib_file)
end

def path
@options.path || "#{File.basename(Dir.pwd)}.apib"
end
Expand All @@ -57,7 +62,7 @@ def query_apiary(host, path)
url = "https://#{host}/blueprint/publish/#{@options.api_name}"
if validate_apib_file path
data = {
:code => File.read(path),
:code => get_apib_file(path),
:messageToSave => @options.commit_message
}
RestClient.proxy = @options.proxy
Expand Down
13 changes: 11 additions & 2 deletions lib/apiary/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,21 @@ class Common
def initialize()
end

def get_apib_file(apib_file)
if validate_apib_file(apib_file)
text_without_bom = nil
File.open(apib_file, "r:bom|utf-8") { |file|
text_without_bom = file.read
}
text_without_bom
end
end

def validate_apib_file(apib_file)
unless File.exist?(apib_file)
raise "Apiary definition file hasn't been found: #{apib_file.inspect}"
end
File.read(apib_file)
true
end

end
end
10 changes: 10 additions & 0 deletions spec/common_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,14 @@

end

describe 'Test get file with and without BOM' do

it 'get file and compare' do
common = Apiary::Common.new
file1 = common.get_apib_file('features/fixtures/apiary.apib')
file2 = common.get_apib_file('features/fixtures/apiary_with_bom.apib')
expect(file1).to eq(file2)
end
end

end

0 comments on commit d45ec0d

Please sign in to comment.