Class: HipChat::ApiVersion::Client
- Inherits:
-
HipChat::ApiVersion
- Object
- HipChat::ApiVersion
- HipChat::ApiVersion::Client
- Defined in:
- lib/hipchat/api_version.rb
Instance Attribute Summary collapse
-
#base_uri ⇒ Object
readonly
Returns the value of attribute base_uri.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #create_room_config ⇒ Object
- #create_user_config ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #rooms_config ⇒ Object
- #scopes_config ⇒ Object
- #users_config ⇒ Object
Methods inherited from HipChat::ApiVersion
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/hipchat/api_version.rb', line 16 def initialize( = {}) # puts options.inspect @version = [:api_version] if @version.eql?('v1') @base_uri = "#{options[:server_url]}/v1" @headers = {'Accept' => 'application/json', 'Content-Type' => 'application/x-www-form-urlencoded'} elsif @version.eql?('v2') @base_uri = "#{options[:server_url]}/v2" @headers = {'Accept' => 'application/json', 'Content-Type' => 'application/json'} else raise InvalidApiVersion, 'Couldn\'t recognize API version' end end |
Instance Attribute Details
#base_uri ⇒ Object (readonly)
Returns the value of attribute base_uri.
32 33 34 |
# File 'lib/hipchat/api_version.rb', line 32 def base_uri @base_uri end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
32 33 34 |
# File 'lib/hipchat/api_version.rb', line 32 def headers @headers end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
32 33 34 |
# File 'lib/hipchat/api_version.rb', line 32 def version @version end |
Instance Method Details
#create_room_config ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/hipchat/api_version.rb', line 48 def create_room_config { 'v1' => { :url => '/rooms/create', :body_format => :to_hash }, 'v2' => { :url => '/room', :body_format => :to_json } }[version] end |
#create_user_config ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/hipchat/api_version.rb', line 61 def create_user_config { 'v1' => { :url => '/users/create', :body_format => :to_hash }, 'v2' => { :url => '/user', :body_format => :to_json } }[version] end |
#rooms_config ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/hipchat/api_version.rb', line 34 def rooms_config { 'v1' => { :url => '/rooms/list', :data_key => 'rooms' }, 'v2' => { :url => '/room', :data_key => 'items' } }[version] end |
#scopes_config ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/hipchat/api_version.rb', line 87 def scopes_config raise InvalidApiVersion, 'This functionality is not supported in API v1' unless version.eql?('v2') { 'v2' => { :url => URI::escape("/oauth/token") } }[version] end |
#users_config ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/hipchat/api_version.rb', line 74 def users_config { 'v1' => { :url => '/users/list', :data_key => 'users' }, 'v2' => { :url => '/user', :data_key => 'items' } }[version] end |