hipchat-api 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm 1.9.2@hipchat-api
data/CHANGLOG.markdown ADDED
@@ -0,0 +1,3 @@
1
+ # hipchat-api 1.0.0
2
+
3
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,20 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.3.0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.6.0"
12
+ gem "rcov", ">= 0"
13
+ end
14
+
15
+ group :test do
16
+ gem 'mocha'
17
+ gem 'fakeweb'
18
+ end
19
+
20
+ gem 'httparty'
data/Gemfile.lock ADDED
@@ -0,0 +1,36 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ crack (0.1.8)
5
+ diff-lcs (1.1.2)
6
+ fakeweb (1.3.0)
7
+ git (1.2.5)
8
+ httparty (0.7.7)
9
+ crack (= 0.1.8)
10
+ jeweler (1.6.0)
11
+ bundler (~> 1.0.0)
12
+ git (>= 1.2.5)
13
+ rake
14
+ mocha (0.9.12)
15
+ rake (0.8.7)
16
+ rcov (0.9.9)
17
+ rspec (2.3.0)
18
+ rspec-core (~> 2.3.0)
19
+ rspec-expectations (~> 2.3.0)
20
+ rspec-mocks (~> 2.3.0)
21
+ rspec-core (2.3.0)
22
+ rspec-expectations (2.3.0)
23
+ diff-lcs (~> 1.1.2)
24
+ rspec-mocks (2.3.0)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ bundler (~> 1.0.0)
31
+ fakeweb
32
+ httparty
33
+ jeweler (~> 1.6.0)
34
+ mocha
35
+ rcov
36
+ rspec (~> 2.3.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 David Czarnecki
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = hipchat-api
2
+
3
+ Ruby API for interacting with HipChat API, https://www.hipchat.com/docs/api
4
+
5
+ == Contributing to hipchat-api
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 David Czarnecki. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "hipchat-api"
18
+ gem.homepage = "http://github.com/czarneckid/hipchat-api"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Ruby API for interacting with HipChat}
21
+ gem.description = %Q{Ruby API for interacting with HipChat}
22
+ gem.email = "czarneckid@acm.org"
23
+ gem.authors = ["David Czarnecki"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rake/rdoctask'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "hipchat-api #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,74 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{hipchat-api}
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["David Czarnecki"]
12
+ s.date = %q{2011-05-07}
13
+ s.description = %q{Ruby API for interacting with HipChat}
14
+ s.email = %q{czarneckid@acm.org}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ ".rvmrc",
23
+ "CHANGLOG.markdown",
24
+ "Gemfile",
25
+ "Gemfile.lock",
26
+ "LICENSE.txt",
27
+ "README.rdoc",
28
+ "Rakefile",
29
+ "VERSION",
30
+ "hipchat-api.gemspec",
31
+ "lib/hipchat-api.rb",
32
+ "spec/fakeweb/rooms_history_response.json",
33
+ "spec/fakeweb/rooms_list_response.json",
34
+ "spec/fakeweb/rooms_message_response.json",
35
+ "spec/fakeweb/rooms_show_response.json",
36
+ "spec/fakeweb/users_create_response.json",
37
+ "spec/fakeweb/users_delete_response.json",
38
+ "spec/fakeweb/users_list_response.json",
39
+ "spec/fakeweb/users_show_response.json",
40
+ "spec/fakeweb/users_update_response.json",
41
+ "spec/hipchat-api_spec.rb",
42
+ "spec/spec_helper.rb"
43
+ ]
44
+ s.homepage = %q{http://github.com/czarneckid/hipchat-api}
45
+ s.licenses = ["MIT"]
46
+ s.require_paths = ["lib"]
47
+ s.rubygems_version = %q{1.6.2}
48
+ s.summary = %q{Ruby API for interacting with HipChat}
49
+
50
+ if s.respond_to? :specification_version then
51
+ s.specification_version = 3
52
+
53
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
54
+ s.add_runtime_dependency(%q<httparty>, [">= 0"])
55
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
56
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
57
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
58
+ s.add_development_dependency(%q<rcov>, [">= 0"])
59
+ else
60
+ s.add_dependency(%q<httparty>, [">= 0"])
61
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
62
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
63
+ s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
64
+ s.add_dependency(%q<rcov>, [">= 0"])
65
+ end
66
+ else
67
+ s.add_dependency(%q<httparty>, [">= 0"])
68
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
69
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
70
+ s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
71
+ s.add_dependency(%q<rcov>, [">= 0"])
72
+ end
73
+ end
74
+
@@ -0,0 +1,96 @@
1
+ require 'httparty'
2
+
3
+ module HipChat
4
+ class API
5
+ include HTTParty
6
+
7
+ VERSION = '1.0.0'.freeze
8
+ DEFAULT_TIMEOUT = 3
9
+
10
+ DEFAULT_HEADERS = {
11
+ 'User-Agent' => "HipChat gem #{VERSION}",
12
+ }
13
+
14
+ headers(DEFAULT_HEADERS)
15
+ default_timeout(DEFAULT_TIMEOUT)
16
+ format(:json)
17
+
18
+ HIPCHAT_API_URL = 'http://api.hipchat.com/v1'
19
+
20
+ attr_accessor :hipchat_api_url
21
+ attr_accessor :token
22
+
23
+ def initialize(token, hipchat_api_url = HIPCHAT_API_URL)
24
+ @token = token
25
+ @hipchat_api_url = hipchat_api_url
26
+ end
27
+
28
+ def debug(location = $stderr)
29
+ self.class.debug_output(location)
30
+ end
31
+
32
+ def set_http_headers(http_headers = {})
33
+ http_headers.merge!(DEFAULT_HEADERS)
34
+ self.class.headers(http_headers)
35
+ end
36
+
37
+ def set_timeout(timeout)
38
+ self.class.default_timeout(timeout)
39
+ end
40
+
41
+ # https://www.hipchat.com/docs/api/method/rooms/history
42
+ def rooms_history(room_id, date, timezone)
43
+ self.class.get(hipchat_api_url_for('rooms/history'), :query => {:auth_token => @token, :room_id => room_id, :date => date,
44
+ :timezone => timezone})
45
+ end
46
+
47
+ # https://www.hipchat.com/docs/api/method/rooms/list
48
+ def rooms_list
49
+ self.class.get(hipchat_api_url_for('rooms/list'), :query => {:auth_token => @token})
50
+ end
51
+
52
+ # https://www.hipchat.com/docs/api/method/rooms/message
53
+ def rooms_message(room_id, from, message, notify = 0, color = 'yellow')
54
+ self.class.post(hipchat_api_url_for('rooms/message'), :body => {:auth_token => @token, :room_id => room_id, :from => from,
55
+ :message => message, :notify => notify, :color => color})
56
+ end
57
+
58
+ # https://www.hipchat.com/docs/api/method/rooms/show
59
+ def rooms_show(room_id)
60
+ self.class.get(hipchat_api_url_for('rooms/show'), :query => {:auth_token => @token, :room_id => room_id})
61
+ end
62
+
63
+ # https://www.hipchat.com/docs/api/method/users/create
64
+ def users_create(email, name, title, is_group_admin = 0, password = nil, timezone = 'UTC')
65
+ self.class.post(hipchat_api_url_for('users/create'), :body => {:auth_token => @token, :email => email, :name => name, :title => title,
66
+ :is_group_admin => is_group_admin, :password => password, :timezone => timezone}.reject!{|key, value| value.nil?})
67
+ end
68
+
69
+ # https://www.hipchat.com/docs/api/method/users/delete
70
+ def users_delete(user_id)
71
+ self.class.post(hipchat_api_url_for('users/delete'), :body => {:auth_token => @token, :user_id => user_id})
72
+ end
73
+
74
+ # https://www.hipchat.com/docs/api/method/users/list
75
+ def users_list
76
+ self.class.get(hipchat_api_url_for('users/list'), :query => {:auth_token => @token})
77
+ end
78
+
79
+ # https://www.hipchat.com/docs/api/method/users/show
80
+ def users_show(user_id)
81
+ self.class.get(hipchat_api_url_for('users/show'), :query => {:auth_token => @token, :user_id => user_id})
82
+ end
83
+
84
+ # https://www.hipchat.com/docs/api/method/users/update
85
+ def users_update(user_id, email = nil, name = nil, title = nil, is_group_admin = nil, password = nil, timezone = nil)
86
+ self.class.post(hipchat_api_url_for('users/update'), :body => {:auth_token => @token, :user_id => user_id, :email => email,
87
+ :name => name, :title => title, :is_group_admin => is_group_admin, :password => password, :timezone => timezone}.reject!{|key, value| value.nil?})
88
+ end
89
+
90
+ private
91
+
92
+ def hipchat_api_url_for(method)
93
+ "#{@hipchat_api_url}/#{method}"
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,23 @@
1
+ { "messages" : [ { "date" : "2010-11-19T15:48:19-0800",
2
+ "from" : { "name" : "Garret Heaton",
3
+ "user_id" : 10
4
+ },
5
+ "message" : "Good morning! This is a regular message."
6
+ },
7
+ { "date" : "2010-11-19T15:49:44-0800",
8
+ "file" : { "name" : "Screenshot.png",
9
+ "size" : 141909,
10
+ "url" : "http://uploads.hipchat.com/xxx/Screenshot.png"
11
+ },
12
+ "from" : { "name" : "Garret Heaton",
13
+ "user_id" : 10
14
+ },
15
+ "message" : "This is a file upload"
16
+ },
17
+ { "date" : "2010-11-19T16:13:40-0800",
18
+ "from" : { "name" : "Deploy Bot",
19
+ "user_id" : "api"
20
+ },
21
+ "message" : "This message is sent via the API so the user_id is 'api'."
22
+ }
23
+ ] }
@@ -0,0 +1,13 @@
1
+ { "rooms" : [ { "last_active" : 1269020400,
2
+ "name" : "Development",
3
+ "owner_user_id" : 1,
4
+ "room_id" : 7,
5
+ "topic" : "Make sure to document your API functions well!"
6
+ },
7
+ { "last_active" : 1269010500,
8
+ "name" : "Ops",
9
+ "owner_user_id" : 5,
10
+ "room_id" : 10,
11
+ "topic" : "Chef is so awesome."
12
+ }
13
+ ] }
@@ -0,0 +1 @@
1
+ { "status": "sent" }
@@ -0,0 +1,14 @@
1
+ { "room" : { "created" : 1269010311,
2
+ "last_active" : 1269020400,
3
+ "name" : "Ops",
4
+ "owner_user_id" : 5,
5
+ "participants" : [ { "name" : "Garret Heaton",
6
+ "user_id" : 5
7
+ },
8
+ { "name" : "Chris Rivers",
9
+ "user_id" : 1
10
+ }
11
+ ],
12
+ "room_id" : 5,
13
+ "topic" : "Chef is so awesome."
14
+ } }
@@ -0,0 +1,10 @@
1
+ { "user" : { "email" : "new@company.com",
2
+ "is_group_admin" : 0,
3
+ "name" : "New Guy",
4
+ "password" : "d294H58zlE",
5
+ "photo_url" : "https://www.hipchat.com/img/silhouette_125.png",
6
+ "status" : "offline",
7
+ "status_message" : "",
8
+ "title" : "Intern",
9
+ "user_id" : 3
10
+ } }
@@ -0,0 +1 @@
1
+ { "deleted": true }
@@ -0,0 +1,28 @@
1
+ { "users" : [ { "email" : "chris@hipchat.com",
2
+ "is_group_admin" : 1,
3
+ "name" : "Chris Rivers",
4
+ "photo_url" : "https://www.hipchat.com/chris.png",
5
+ "status" : "away",
6
+ "status_message" : "gym, bbl",
7
+ "title" : "Developer",
8
+ "user_id" : 1
9
+ },
10
+ { "email" : "pete@hipchat.com",
11
+ "is_group_admin" : 1,
12
+ "name" : "Peter Curley",
13
+ "photo_url" : "https://www.hipchat.com/pete.png",
14
+ "status" : "offline",
15
+ "status_message" : "",
16
+ "title" : "Designer",
17
+ "user_id" : 3
18
+ },
19
+ { "email" : "garret@hipchat.com",
20
+ "is_group_admin" : 1,
21
+ "name" : "Garret Heaton",
22
+ "photo_url" : "https://www.hipchat.com/garret.png",
23
+ "status" : "available",
24
+ "status_message" : "Come see what I'm working on!",
25
+ "title" : "Co-founder",
26
+ "user_id" : 5
27
+ }
28
+ ] }
@@ -0,0 +1,9 @@
1
+ { "user" : { "email" : "garret@hipchat.com",
2
+ "is_group_admin" : 1,
3
+ "name" : "Garret Heaton",
4
+ "photo_url" : "https://www.hipchat.com/img/silhouette_125.png",
5
+ "status" : "available",
6
+ "status_message" : "Come see what I'm working on!",
7
+ "title" : "Co-founder",
8
+ "user_id" : 5
9
+ } }
@@ -0,0 +1,9 @@
1
+ { "user" : { "email" : "new-email-address@hipchat.com",
2
+ "is_group_admin" : 1,
3
+ "name" : "Garret Heaton",
4
+ "photo_url" : "https://www.hipchat.com/img/silhouette_125.png",
5
+ "status" : "available",
6
+ "status_message" : "Come see what I'm working on!",
7
+ "title" : "Co-founder",
8
+ "user_id" : 5
9
+ } }
@@ -0,0 +1,134 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'fakeweb'
3
+
4
+ describe "HipChat::API" do
5
+ before(:each) do
6
+ FakeWeb.allow_net_connect = false
7
+ FakeWeb.clean_registry
8
+ @hipchat_api = HipChat::API.new('token')
9
+ end
10
+
11
+ it "should be the correct version" do
12
+ HipChat::API::VERSION.should == '1.0.0'
13
+ end
14
+
15
+ it "should create a new instance with the correct parameters" do
16
+ @hipchat_api.token.should == 'token'
17
+ @hipchat_api.hipchat_api_url.should == HipChat::API::HIPCHAT_API_URL
18
+ end
19
+
20
+ it "should allow http headers to be set" do
21
+ @hipchat_api.expects(:headers).at_least_once
22
+
23
+ @hipchat_api.set_http_headers({'Accept' => 'application/json'})
24
+ end
25
+
26
+ it "should allow a timeout to be set" do
27
+ @hipchat_api.expects(:default_timeout).at_least_once
28
+
29
+ @hipchat_api.set_timeout(10)
30
+ end
31
+
32
+ it "should return a list of rooms" do
33
+ FakeWeb.register_uri(:get,
34
+ %r|#{HipChat::API::HIPCHAT_API_URL}/rooms/list|,
35
+ :body => File.join(File.dirname(__FILE__), 'fakeweb', 'rooms_list_response.json'),
36
+ :content_type => "application/json")
37
+
38
+ rooms_list_response = @hipchat_api.rooms_list
39
+ rooms_list_response.should_not be nil
40
+ rooms_list_response['rooms'].size.should be 2
41
+ end
42
+
43
+ it "should return the correct room informaton for a room_id" do
44
+ FakeWeb.register_uri(:get,
45
+ %r|#{HipChat::API::HIPCHAT_API_URL}/rooms/show|,
46
+ :body => File.join(File.dirname(__FILE__), 'fakeweb', 'rooms_show_response.json'),
47
+ :content_type => "application/json")
48
+
49
+ rooms_show_response = @hipchat_api.rooms_show(7)
50
+ rooms_show_response.should_not be nil
51
+ rooms_show_response['room']['topic'].should == 'Chef is so awesome.'
52
+ end
53
+
54
+ it "should send a message" do
55
+ FakeWeb.register_uri(:post,
56
+ %r|#{HipChat::API::HIPCHAT_API_URL}/rooms/message|,
57
+ :body => File.join(File.dirname(__FILE__), 'fakeweb', 'rooms_message_response.json'),
58
+ :content_type => "application/json")
59
+
60
+ rooms_message_response = @hipchat_api.rooms_message(10, 'Alerts', 'A new user signed up')
61
+ rooms_message_response.should_not be nil
62
+ rooms_message_response['status'].should == 'sent'
63
+ end
64
+
65
+ it "should return a history of messages" do
66
+ FakeWeb.register_uri(:get,
67
+ %r|#{HipChat::API::HIPCHAT_API_URL}/rooms/history|,
68
+ :body => File.join(File.dirname(__FILE__), 'fakeweb', 'rooms_history_response.json'),
69
+ :content_type => "application/json")
70
+
71
+ rooms_history_response = @hipchat_api.rooms_history(10, '2010-11-19', 'PST')
72
+ rooms_history_response.should_not be nil
73
+ rooms_history_response['messages'].size.should be 3
74
+ end
75
+
76
+ it "should create a user" do
77
+ FakeWeb.register_uri(:post,
78
+ %r|#{HipChat::API::HIPCHAT_API_URL}/users/create|,
79
+ :body => File.join(File.dirname(__FILE__), 'fakeweb', 'users_create_response.json'),
80
+ :content_type => "application/json")
81
+
82
+ users_create_response = @hipchat_api.users_create('new@company.com', 'New Guy', 'intern')
83
+ users_create_response.should_not be nil
84
+ users_create_response['user']['name'].should == 'New Guy'
85
+ end
86
+
87
+ it "should delete a user" do
88
+ FakeWeb.register_uri(:post,
89
+ %r|#{HipChat::API::HIPCHAT_API_URL}/users/delete|,
90
+ :body => File.join(File.dirname(__FILE__), 'fakeweb', 'users_delete_response.json'),
91
+ :content_type => "application/json")
92
+
93
+ users_delete_response = @hipchat_api.users_delete(5)
94
+ users_delete_response.should_not be nil
95
+ users_delete_response['deleted'].should be true
96
+ end
97
+
98
+ it "should return a list of users" do
99
+ FakeWeb.register_uri(:get,
100
+ %r|#{HipChat::API::HIPCHAT_API_URL}/users/list|,
101
+ :body => File.join(File.dirname(__FILE__), 'fakeweb', 'users_list_response.json'),
102
+ :content_type => "application/json")
103
+
104
+ users_list_response = @hipchat_api.users_list
105
+ users_list_response.should_not be nil
106
+ users_list_response['users'].size.should be 3
107
+ end
108
+
109
+ it "should show the details for a user" do
110
+ FakeWeb.register_uri(:get,
111
+ %r|#{HipChat::API::HIPCHAT_API_URL}/users/show|,
112
+ :body => File.join(File.dirname(__FILE__), 'fakeweb', 'users_show_response.json'),
113
+ :content_type => "application/json")
114
+
115
+ users_show_response = @hipchat_api.users_show(5)
116
+ users_show_response.should_not be nil
117
+ users_show_response['user']['name'].should == 'Garret Heaton'
118
+ end
119
+
120
+ it "should update a user" do
121
+ FakeWeb.register_uri(:post,
122
+ %r|#{HipChat::API::HIPCHAT_API_URL}/users/update|,
123
+ :body => File.join(File.dirname(__FILE__), 'fakeweb', 'users_update_response.json'),
124
+ :content_type => "application/json")
125
+
126
+ users_update_response = @hipchat_api.users_update(5, 'new-email-address@hipchat.com')
127
+ users_update_response.should_not be nil
128
+ users_update_response['user']['email'].should == 'new-email-address@hipchat.com'
129
+ end
130
+
131
+ after(:each) do
132
+ FakeWeb.allow_net_connect = true
133
+ end
134
+ end
@@ -0,0 +1,13 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'hipchat-api'
5
+ require 'mocha'
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+
11
+ RSpec.configure do |config|
12
+
13
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hipchat-api
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.0.0
6
+ platform: ruby
7
+ authors:
8
+ - David Czarnecki
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-05-07 00:00:00 -04:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: httparty
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: 2.3.0
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: bundler
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.0.0
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: jeweler
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: 1.6.0
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: rcov
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: *id005
71
+ description: Ruby API for interacting with HipChat
72
+ email: czarneckid@acm.org
73
+ executables: []
74
+
75
+ extensions: []
76
+
77
+ extra_rdoc_files:
78
+ - LICENSE.txt
79
+ - README.rdoc
80
+ files:
81
+ - .document
82
+ - .rspec
83
+ - .rvmrc
84
+ - CHANGLOG.markdown
85
+ - Gemfile
86
+ - Gemfile.lock
87
+ - LICENSE.txt
88
+ - README.rdoc
89
+ - Rakefile
90
+ - VERSION
91
+ - hipchat-api.gemspec
92
+ - lib/hipchat-api.rb
93
+ - spec/fakeweb/rooms_history_response.json
94
+ - spec/fakeweb/rooms_list_response.json
95
+ - spec/fakeweb/rooms_message_response.json
96
+ - spec/fakeweb/rooms_show_response.json
97
+ - spec/fakeweb/users_create_response.json
98
+ - spec/fakeweb/users_delete_response.json
99
+ - spec/fakeweb/users_list_response.json
100
+ - spec/fakeweb/users_show_response.json
101
+ - spec/fakeweb/users_update_response.json
102
+ - spec/hipchat-api_spec.rb
103
+ - spec/spec_helper.rb
104
+ has_rdoc: true
105
+ homepage: http://github.com/czarneckid/hipchat-api
106
+ licenses:
107
+ - MIT
108
+ post_install_message:
109
+ rdoc_options: []
110
+
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ hash: -3182576357010915780
119
+ segments:
120
+ - 0
121
+ version: "0"
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: "0"
128
+ requirements: []
129
+
130
+ rubyforge_project:
131
+ rubygems_version: 1.6.2
132
+ signing_key:
133
+ specification_version: 3
134
+ summary: Ruby API for interacting with HipChat
135
+ test_files: []
136
+