hip_chat 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OTM5YjU0MmYzOTgxZmEyNWY2NDE1MTg5MGIwYWJhNjdiMjI1N2FmMw==
5
+ data.tar.gz: !binary |-
6
+ YjVjNzFlZDY2NzA1ZWNlZjI4YmQ2MmQzYzdlYzEwNTgyOWJiYTE5ZQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MGEwZjBmZDEzODQ0NTJmODgxOWQ5YmExNzJiYmIyZTU2NzliMjJkOGMzMjVm
10
+ ZDE1MjI5NTVmNzE1OTk2YmQ3ZWJiNDk2ZGIyYTBkOTYzZDZkMzcwNDAzYmNi
11
+ OTFlY2I2MjhlMmFmY2IzMGRmNWUwNDU3ZWQ2ZWQ4ZDNjNmNlNzY=
12
+ data.tar.gz: !binary |-
13
+ YTcwMDcwZDk4ZmVkNzk5NDAwODUwNDIxZTEyODlmYWRhYjM5ZTQxMThkZDlk
14
+ ZjY5M2Q1ODFlZDdmYjZhYWEwNDgzODExZmRkMmMzNWFkMjgyMDkwMjI5YTRj
15
+ OTg5M2Y2ZmU5MzQxMjAzN2FjYmQ2MzM2NmMwNzA0OTI1Y2QwMjM=
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.swp
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ hip_chat
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 1.9.3
data/.travis.yml ADDED
@@ -0,0 +1,16 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.2.0
6
+ env: RAKE_ENV=test RAILS_ENV=test
7
+ before_install:
8
+ - 'gem install bundler'
9
+ script:
10
+ - 'bundle exec rspec'
11
+ notifications:
12
+ email:
13
+ recipients:
14
+ - humzashah+travis@gmail.com
15
+ on_success: never
16
+ on_failure: always
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hip_chat.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # HipChat
2
+
3
+ Easily control [HipChat](https://www.hipchat.com) with Ruby.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'hip_chat'
11
+ ```
12
+
13
+ and run `bundle install`
14
+
15
+ ## Features
16
+
17
+ Currently, this gem lets you view, edit, create, and destroy users on HipChat.
18
+
19
+ ## Features for the Near Future
20
+
21
+ Providing more methods to interact with HipChat. The long-term plan is to cover all of the interactions possible with [HipChat API v2](https://www.hipchat.com/docs/apiv2).
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ @api = HipChat::Api.new(authorization_token)
27
+
28
+ # get list of users:
29
+ @users = @api.users
30
+
31
+ # find users by id, email, or mention_name:
32
+ finder = {
33
+ mention_name: "SyedHumzaShah"
34
+ } # or {id: id} or {email: email}
35
+ user = @users.find(mention_name: "SyedHumzaShah")
36
+ # ^ alternate: HipChat::User.find(token, finder)
37
+
38
+ # create new users:
39
+ attributes = {
40
+ email: "some_email@domain.com",
41
+ name: "Syed Humza Shah",
42
+ password: some_password
43
+ }
44
+ user = @users.create!(attributes) # or @users.create(attributes)
45
+ # ^ alternate: HipChat::User.create(token, attributes)
46
+
47
+ # update users:
48
+ user.name = "Syed Humza"
49
+ user.save! # or user.save
50
+
51
+ # delete a user:
52
+ user.destroy! # or user.destroy
53
+
54
+ # refresh users' list
55
+ @api.refresh_users
56
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "hip_chat"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/hip_chat.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hip_chat/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hip_chat"
8
+ spec.version = HipChat::VERSION
9
+ spec.authors = ["Syed Humza Shah"]
10
+ spec.email = ["humzashah+github@gmail.com"]
11
+
12
+ spec.summary = "Use Ruby to control HipChat."
13
+ spec.description = "Easily communicate with HipChat using via their API's v2."
14
+ spec.homepage = "https://github.com/humzashah/hip_chat"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.required_ruby_version = '>= 1.9.3'
22
+
23
+ spec.add_development_dependency "bundler", ">= 1.8"
24
+ spec.add_development_dependency "rake", ">= 10.0"
25
+ spec.add_development_dependency "httparty"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "webmock"
28
+ end
data/lib/hip_chat.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "hip_chat/version"
2
+
3
+ module HipChat
4
+ end
5
+
6
+ parent_folder = Pathname.new(__FILE__).parent.to_s
7
+ Dir[File.join(parent_folder, "hip_chat", "*.rb")].each { |path| require(path) }
@@ -0,0 +1,29 @@
1
+ require_relative "common_methods"
2
+ require_relative "user"
3
+ require_relative "relation"
4
+
5
+ module HipChat
6
+ class Api
7
+ include CommonMethods
8
+
9
+ attr_reader :token, :users
10
+
11
+ def initialize(token)
12
+ @token = token
13
+ validate_token
14
+ end
15
+
16
+ def refresh_users
17
+ response = get_request(User::URL, auth_hash)
18
+ users_list = validate_response(response)["items"]
19
+
20
+ @users = Relation.new(token, users_list, User)
21
+ end
22
+
23
+ private
24
+
25
+ def validate_token
26
+ refresh_users
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,57 @@
1
+ require "httparty"
2
+ require_relative "error"
3
+
4
+ module HipChat
5
+ module CommonMethods
6
+ BASE_URL = "http://api.hipchat.com/v2/"
7
+
8
+ OK_CODES = [
9
+ 200,
10
+ 201,
11
+ 204
12
+ ]
13
+
14
+ private
15
+
16
+ def auth_hash
17
+ {auth_token: token}
18
+ end
19
+
20
+ def get_request(url, query_hash)
21
+ HTTParty.get(url, query: auth_hash.merge(query_hash))
22
+ end
23
+
24
+ def put_request(url, data)
25
+ put_or_post_data(:put, url, data)
26
+ end
27
+
28
+ def post_request(url, data)
29
+ put_or_post_data(:post, url, data)
30
+ end
31
+
32
+ def put_or_post_data(type, url, data)
33
+ HTTParty.public_send(type, url, {
34
+ body: data.to_json,
35
+ headers: {'Content-Type' => 'application/json'},
36
+ query: auth_hash
37
+ })
38
+ end
39
+
40
+ def deletion_request(url)
41
+ HTTParty.delete(url, query: auth_hash)
42
+ end
43
+
44
+ def validate_response(response)
45
+ body = response.body
46
+ body_hash = JSON.parse(response.body) if body
47
+
48
+ if OK_CODES.include?(response.code)
49
+ body_hash
50
+ else
51
+ error = body_hash["error"]
52
+ raise Error.new(error)
53
+ end
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,4 @@
1
+ module HipChat
2
+ class Error < StandardError
3
+ end
4
+ end
@@ -0,0 +1,24 @@
1
+ module HipChat
2
+ class Relation < Array
3
+ def initialize(token, list, list_class)
4
+ super(list)
5
+
6
+ @token = token
7
+ @list_class = list_class
8
+
9
+ self.map! do |element|
10
+ list_class.new(@token, element)
11
+ end
12
+ end
13
+
14
+ %w{
15
+ find
16
+ create
17
+ create!
18
+ }.each do |method_name|
19
+ define_method method_name do |*args|
20
+ @list_class.public_send(method_name, @token, *args)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,131 @@
1
+ require_relative "common_methods"
2
+
3
+ module HipChat
4
+ class User
5
+ include CommonMethods
6
+
7
+ URL = BASE_URL + "user"
8
+
9
+ ATTRIBUTES = %w{
10
+ client
11
+ created
12
+ email
13
+ group
14
+ id
15
+ idle
16
+ is_deleted
17
+ is_group_admin
18
+ is_guest
19
+ is_online
20
+ last_active
21
+ links
22
+ mention_name
23
+ name
24
+ password
25
+ photo_url
26
+ presence
27
+ show
28
+ status
29
+ timezone
30
+ title
31
+ token
32
+ type
33
+ version
34
+ xmpp_jid
35
+ }
36
+
37
+ attr_accessor *ATTRIBUTES
38
+
39
+ class << self
40
+ # finder can be {id: id}, {email: email}, or {mention_name: mention_name}
41
+
42
+ def find(token, finder)
43
+ self.new(token, finder, fetch_details: true)
44
+ end
45
+
46
+ def create!(token, attributes)
47
+ new(token, attributes).tap(&:save!)
48
+ end
49
+
50
+ def create(token, attributes)
51
+ begin
52
+ create!(token, attributes)
53
+ rescue Error
54
+ false
55
+ end
56
+ end
57
+ end
58
+
59
+ def details
60
+ response = get_request(url, auth_hash)
61
+ properties_hash = validate_response(response)
62
+ set_properties(properties_hash)
63
+ end
64
+
65
+ def save!
66
+ if id.nil?
67
+ response = post_request(URL, hash_for_update)
68
+ validate_response(response)
69
+ true
70
+ else
71
+ update!
72
+ end
73
+ end
74
+
75
+ def update!
76
+ response = put_request(url, hash_for_update)
77
+ validate_response(response)
78
+ details
79
+ true
80
+ end
81
+
82
+ def destroy!
83
+ response = deletion_request(url)
84
+ validate_response(response)
85
+ true
86
+ end
87
+
88
+ {
89
+ destroy: "destroy!",
90
+ save: "save!",
91
+ update: "update!"
92
+ }.each do |rescuer, breaker|
93
+ define_method rescuer do
94
+ begin
95
+ send(breaker)
96
+ rescue Error => @error
97
+ false
98
+ end
99
+ end
100
+ end
101
+
102
+ private
103
+
104
+ def initialize(token, properties_hash, opts={})
105
+ @token = token
106
+ set_properties(properties_hash)
107
+ details if opts[:fetch_details]
108
+ end
109
+
110
+ def url
111
+ attr = id || email || "@#{mention_name}"
112
+ URL + "/" + attr.to_s
113
+ end
114
+
115
+ def set_properties(hash)
116
+ hash.each do |key, value|
117
+ var_name = "@#{key}"
118
+ self.instance_variable_set(var_name, value)
119
+ end
120
+
121
+ self
122
+ end
123
+
124
+ def hash_for_update
125
+ ATTRIBUTES.each_with_object({}) do |method, hash|
126
+ next unless value = public_send(method)
127
+ hash[method] = value
128
+ end
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,3 @@
1
+ module HipChat
2
+ VERSION = "0.1.2"
3
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hip_chat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Syed Humza Shah
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: httparty
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Easily communicate with HipChat using via their API's v2.
84
+ email:
85
+ - humzashah+github@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .ruby-gemset
92
+ - .ruby-version
93
+ - .travis.yml
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - hip_chat.gemspec
101
+ - lib/hip_chat.rb
102
+ - lib/hip_chat/api.rb
103
+ - lib/hip_chat/common_methods.rb
104
+ - lib/hip_chat/error.rb
105
+ - lib/hip_chat/relation.rb
106
+ - lib/hip_chat/user.rb
107
+ - lib/hip_chat/version.rb
108
+ homepage: https://github.com/humzashah/hip_chat
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: 1.9.3
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.4.3
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Use Ruby to control HipChat.
132
+ test_files: []