Skip to content

Commit

Permalink
Experiment with V2 static helpers
Browse files Browse the repository at this point in the history
This feature is also under experiment in the Go client. For now, as the
Go client, I'll only add support for the Whoami method.

More methods will be added in the future if the design of this client
feature makes sense.
  • Loading branch information
weppos committed Mar 9, 2016
1 parent 130db31 commit 70d8e59
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
2 changes: 0 additions & 2 deletions lib/dnsimple.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'httparty'

module Dnsimple

# Echoes a deprecation warning message.
Expand Down
1 change: 1 addition & 0 deletions lib/dnsimple/client.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'httparty'
require 'dnsimple/extra'
require 'dnsimple/struct'
require 'dnsimple/response'
Expand Down
9 changes: 9 additions & 0 deletions lib/dnsimple/client/clients.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,13 @@ class WebhooksService < ClientService
end

end

# This module exposes static helpers for the API v2.
#
# Compared to the full, extended API methods provided by the various client services,
# these static methods return directly the underlying data objects.
# Therefore, it's not possible to access response metadata such as throttling or pagination info.
module V2
extend Client::Identity::StaticHelpers
end
end
17 changes: 16 additions & 1 deletion lib/dnsimple/client/identity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Identity

# Gets the information about the current authenticated context.
#
# @see https://developer.dnsimple.com/v2/identity/
# @see https://developer.dnsimple.com/v2/identity/#whoami
#
# @param [Hash] options
# @return [Dnsimple::Response<Hash>]
Expand All @@ -18,6 +18,21 @@ def whoami(options = {})
Response.new(response, { account: account, user: user })
end


module StaticHelpers
# Calls {Identity#whoami} and directly returns the response data.
#
# @see https://developer.dnsimple.com/v2/identity/#whoami
#
# @param [Dnsimple::Client] client the DNSimple client instance to use
# @param [Array] args the args for the {Identity#whoami} call
# @return [Hash]
# @raise [Dnsimple::RequestError]
def whoami(client, *args)
client.identity.whoami(*args).data
end
end

end
end
end

0 comments on commit 70d8e59

Please sign in to comment.