Skip to content

Commit

Permalink
pass an appID parameter on every request to keep usage stats
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimeiniesta committed Apr 28, 2015
1 parent 7223afc commit c8bc429
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,19 @@ The `issues` array contains all issues returned by the checker, but you'll typic

By default, Mortise will query the Tenon.io API at http://tenon.io/api/ but if you're using your own Tenon Enterprise instance you can set its location like this:

```ruby
Mortise.check('http://example.com', 'YOUR-API-KEY', tenon_uri: 'http://yourchecker.com')
```

## Specifying a different Tenon App ID

By default, Mortise will pass its own identifier on the `appID` parameter, so that Tenon can keep usage stats for Mortise.

If you want to use a different value, you can override it like this:

```ruby
Mortise.check('http://example.com', 'YOUR-API-KEY', tenon_app_id: 'your-app-id')
```

## Development

Expand Down
2 changes: 2 additions & 0 deletions lib/mortise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
require "mortise/errors"

module Mortise
TENON_APP_ID = '490866e2ad3b501842cef0569e4c0ee0'

def self.check(url, key, options = {})
Mortise::Checker.new(url, key, options)
end
Expand Down
9 changes: 5 additions & 4 deletions lib/mortise/checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@

module Mortise
class Checker
attr_reader :url, :tenon_uri, :key
attr_reader :url, :tenon_uri, :key, :tenon_app_id

def initialize(url, key, options = {})
options = defaults.merge(options)

@url = url
@key = key

@tenon_uri = options[:tenon_uri]
@tenon_uri = options[:tenon_uri]
@tenon_app_id = options[:tenon_app_id]
end

def raw
Expand All @@ -33,7 +34,7 @@ def warnings
private

def defaults
{ tenon_uri: 'https://tenon.io/api/' }
{ tenon_uri: 'https://tenon.io/api/', tenon_app_id: Mortise::TENON_APP_ID }
end

def response
Expand All @@ -43,7 +44,7 @@ def response
end

def tenon_response
@tenon_response ||= HTTParty.post(tenon_uri, body: { url: url, key: key },
@tenon_response ||= HTTParty.post(tenon_uri, body: { url: url, key: key, appID: tenon_app_id },
headers: { 'Content-Type' => 'application/x-www-form-urlencoded',
'Cache-Control' => 'no-cache' })
end
Expand Down
9 changes: 9 additions & 0 deletions spec/mortise_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@

expect(checker.tenon_uri).to eq 'http://checker.example.com/'
end

it 'tenon appID can be set' do
checker = Mortise.check('http://validationhell.com', '1234',
tenon_app_id: 'abcde')

stub_tenon_request(200, fixture_file('validationhell.json'), 'abcde')

expect(checker.raw).to eq JSON.parse(fixture_file('validationhell.json'))
end
end

describe 'checking markup' do
Expand Down
4 changes: 2 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ def fixture_file(filename)
File.read(file_path)
end

def stub_tenon_request(status, body)
def stub_tenon_request(status, body, app_id = Mortise::TENON_APP_ID)
stub_request(:post, 'https://tenon.io/api/').
with( body: { key: '1234', url: 'http://validationhell.com' },
with( body: { key: '1234', url: 'http://validationhell.com', appID: app_id },
headers: { 'Cache-Control' => 'no-cache',
'Content-Type' => 'application/x-www-form-urlencoded' }).
to_return(status: status, body: body, headers: {})
Expand Down

0 comments on commit c8bc429

Please sign in to comment.