jibbajabba 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d14d3980345b9f15d53d6ce3d2132625e237c7e5
4
+ data.tar.gz: 93e77c79a9db38611c8c3f786e2451308758744b
5
+ SHA512:
6
+ metadata.gz: aeec94bffc6f202958940a86698ed9728ed49791f92c802d958e247f286e9c1419384bc5d378cbb0c27f775eccd514b019c2546cb5734a286ca96bb42dcd8ece
7
+ data.tar.gz: 3ea3402db5ed3968bedc42281f5a67cd777ce2e03e850573e135bfb28a1fd6ef8ed6ba05caa346437f6761a77d22eca7e96ab4c6efaf6fecaf4f277323d66110
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jibbajabba.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Nathaniel Wroblewski
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,77 @@
1
+ # JibbaJabba
2
+
3
+ JibbaJabba is a fluent Ruby wrapper for the HipChat API using familiar ActiveRecord syntax. For example, you may chain familiar methods like `#all`, `#limit`, or `#offset` as in:
4
+ ```rb
5
+ HipChat::Room.all.offset(25).limit(100)
6
+ ```
7
+ to query the HipChat API at `https://api.hipchat.com/v2/room?start-index=25&max-results=100`.
8
+
9
+ ![Mr. T wants you to quit yo jibbajabba](https://raw.github.com/NathanielWroblewski/jibbajabba/master/mrt.jpg)
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'jibbajabba'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install jibbajabba
24
+
25
+ ## Usage
26
+
27
+ First, set your API key, which you can obtain [here](https://www.hipchat.com/account/api).
28
+
29
+ ```rb
30
+ # set it directly using the attr_accessor
31
+ HipChat.api_key = 'MY HIPCHAT API KEY GOES HERE'
32
+
33
+ # set it by passing a block
34
+ HipChat.configure do |config|
35
+ config.api_key = 'MY HIPCHAT API KEY GOES HERE'
36
+ end
37
+ ```
38
+
39
+ Be safe with API keys. Use environment variables or the [Figaro](https://github.com/laserlemon/figaro) gem or something.
40
+
41
+ There are two HipChat API "models" that you can query: `HipChat::Room` and `HipChat::User`. All queries can be kicked by calling `#to_hash` or any `Hash` or `Enumerable` method on the `HipChat::Room` response object.
42
+
43
+ HipChat::Room
44
+ ---
45
+ Examples:
46
+ ```rb
47
+ # Note that the kicker ('#to_hash', etc.) must be called to hashify the return object or else
48
+ # you'll get a HipChat::Room object which is probably not what you want
49
+ HipChat::Room.all
50
+ # => Returns a HipChat::Room object of all rooms for the user
51
+
52
+ HipChat::Room.all.to_hash
53
+ # => Returns a Ruby Hash of all rooms for the user
54
+
55
+ HipChat::Room.all.each{ |key, value| p "#{key}: #{value}"}
56
+ # => Returns a Ruby Hash and prints all key-value pairs
57
+
58
+ # Construct API queries using familiar ActiveRecord syntax
59
+ HipChat::Room.all.limit(100).offset(25).to_hash
60
+ # => Returns the result (as a Ruby Hash) from querying the API at
61
+ # https://api.hipchat.com/v2/room?start-index=25&max-results=100
62
+ ```
63
+
64
+ Methods:
65
+ ```rb
66
+ HipChat::Room.all # => all rooms for the user, default limit of 100, default start index of 0
67
+ HipChat::Room.all.limit(10) # => change the default limit
68
+ HipChat::Room.all.offset(25) # => change the start index
69
+ ```
70
+
71
+ ## Contributing
72
+
73
+ 1. Fork it ( http://github.com/NathanielWroblewski/jibbajabba/fork )
74
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
75
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
76
+ 4. Push to the branch (`git push origin my-new-feature`)
77
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jibbajabba/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'jibbajabba'
8
+ spec.version = JibbaJabba::VERSION
9
+ spec.authors = ['Nathaniel Wroblewski']
10
+ spec.email = ['NathanielWroblewski@gmail.com']
11
+ spec.summary = %q{Fluent Ruby API wrapper for the HipChat API}
12
+ spec.description = %q{Fluent Ruby API wrapper for the HipChat API}
13
+ spec.homepage = 'https://github.com/NathanielWroblewski/jibbajabba'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.5'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rspec'
24
+ spec.add_development_dependency 'rspec-mocks'
25
+ end
@@ -0,0 +1,5 @@
1
+ require 'jibbajabba/version'
2
+ require 'jibbajabba/hip_chat'
3
+ require 'jibbajabba/room'
4
+ require 'open-uri'
5
+ require 'json'
@@ -0,0 +1,16 @@
1
+ module HipChat
2
+ URL = 'https://api.hipchat.com/v2/'
3
+
4
+ class << self
5
+
6
+ attr_accessor :api_key
7
+
8
+ def configure
9
+ yield self if block_given?
10
+ end
11
+
12
+ def credentials
13
+ {'Authorization' => 'Bearer ' + api_key}
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,50 @@
1
+ module HipChat
2
+ class Room
3
+ class << self
4
+
5
+ undef_method :to_s, :inspect
6
+
7
+ attr_writer :query
8
+
9
+ def query
10
+ @query ||= url
11
+ end
12
+
13
+ def all
14
+ @query = url
15
+ self
16
+ end
17
+ alias_method :list, :all
18
+
19
+ def offset(number)
20
+ @query += "start-index=#{number.to_i}&"
21
+ self
22
+ end
23
+ alias_method :start_index, :offset
24
+
25
+ def limit(number)
26
+ @query += "max-results=#{number.to_i}&"
27
+ self
28
+ end
29
+ alias_method :max_results, :limit
30
+
31
+ def url
32
+ URL + 'room?'
33
+ end
34
+
35
+ def to_hash
36
+ raise 'No API key assigned.' unless HipChat.api_key
37
+ response = open(query, HipChat.credentials){|f| f.read }
38
+ JSON.parse(response)
39
+ end
40
+
41
+ def class
42
+ 'HipChat::Room'
43
+ end
44
+
45
+ def method_missing(method, *args, &block)
46
+ to_hash.send(method, *args, &block)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,3 @@
1
+ module JibbaJabba
2
+ VERSION = "0.0.1"
3
+ end
data/mrt.jpg ADDED
Binary file
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe HipChat, '::URL' do
4
+ it 'returns the api url' do
5
+ expect(HipChat::URL).to eq 'https://api.hipchat.com/v2/'
6
+ end
7
+ end
8
+
9
+ describe HipChat, '.configure' do
10
+ let(:api_key) { SecureRandom.hex }
11
+
12
+ it 'sets the api key when passed a block assigning the key' do
13
+ HipChat.configure{|config| config.api_key = api_key }
14
+
15
+ expect(HipChat.api_key).to eq api_key
16
+ end
17
+ end
18
+
19
+ describe HipChat, '.credentials' do
20
+ let(:api_key) { SecureRandom.hex }
21
+
22
+ it 'returns the API authorization headers' do
23
+ HipChat.api_key = api_key
24
+
25
+ expect(HipChat.credentials).to eq({'Authorization' => "Bearer #{api_key}"})
26
+ end
27
+ end
@@ -0,0 +1,96 @@
1
+ require 'spec_helper'
2
+
3
+ describe HipChat::Room do
4
+ before :each do
5
+ HipChat.api_key = nil
6
+ HipChat::Room.stub(:to_hash)
7
+ HipChat::Room.all
8
+ end
9
+
10
+ describe '.url' do
11
+ it 'returns the API url appended with "room"' do
12
+ api_url = HipChat::URL + 'room?'
13
+
14
+ expect(HipChat::Room.url).to eq api_url
15
+ end
16
+ end
17
+
18
+ describe '.query' do
19
+ it 'defaults to the url' do
20
+ expect(HipChat::Room.query).to eq HipChat::Room.url
21
+ end
22
+ end
23
+
24
+ describe '.all' do
25
+ it 'queries the API for the list of rooms' do
26
+ HipChat::Room.all
27
+
28
+ expect(HipChat::Room.query).to eq HipChat::Room.url
29
+ end
30
+ end
31
+
32
+ describe '.offset' do
33
+ it 'sets the start index for the API query' do
34
+ HipChat::Room.offset(5)
35
+
36
+ expect(HipChat::Room.query).to eq(HipChat::Room.url + 'start-index=5&')
37
+ end
38
+ end
39
+
40
+ describe '.limit' do
41
+ it 'sets the maximum number of results for the API query' do
42
+ HipChat::Room.limit(5)
43
+
44
+ expect(HipChat::Room.query).to eq(HipChat::Room.url + 'max-results=5&')
45
+ end
46
+ end
47
+
48
+ describe '.class' do
49
+ it 'returns HipChat::Room' do
50
+ expect(HipChat::Room.class).to eq 'HipChat::Room'
51
+ end
52
+ end
53
+
54
+ describe '.to_hash' do
55
+ let(:api_key) { SecureRandom.hex }
56
+ let(:api_response) { JSON.dump({ hello: 'world' }) }
57
+
58
+ before :each do
59
+ HipChat::Room.unstub(:to_hash)
60
+ HipChat::Room.stub(:open).and_return(api_response)
61
+ HipChat.api_key = api_key
62
+ end
63
+
64
+ it 'kicks the API query' do
65
+ response = HipChat::Room.all.to_hash
66
+
67
+ expect(HipChat::Room).to have_received(:open).with(
68
+ 'https://api.hipchat.com/v2/room?',
69
+ { 'Authorization' => "Bearer #{api_key}"}
70
+ )
71
+ expect(response).to eq({'hello' => 'world'})
72
+ end
73
+
74
+ it 'kicks chained API queries' do
75
+ HipChat::Room.all.limit(5).offset(7).to_hash
76
+
77
+ expect(HipChat::Room).to have_received(:open).with(
78
+ 'https://api.hipchat.com/v2/room?max-results=5&start-index=7&',
79
+ { 'Authorization' => "Bearer #{api_key}"}
80
+ )
81
+ end
82
+
83
+ it 'errors unless an API key is set' do
84
+ HipChat.api_key = nil
85
+ blah = HipChat::Room rescue nil
86
+
87
+ expect(
88
+ begin
89
+ HipChat::Room.to_hash
90
+ rescue Exception => e
91
+ e.message
92
+ end
93
+ ).to eq 'No API key assigned.'
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'jibbajabba'
4
+ require 'securerandom'
5
+
6
+ RSpec.configure do |config|
7
+ config.treat_symbols_as_metadata_keys_with_true_values = true
8
+ config.run_all_when_everything_filtered = true
9
+ config.filter_run :focus
10
+
11
+ config.order = 'random'
12
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jibbajabba
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nathaniel Wroblewski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-09 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.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
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-mocks
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
+ description: Fluent Ruby API wrapper for the HipChat API
70
+ email:
71
+ - NathanielWroblewski@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .rspec
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - jibbajabba.gemspec
83
+ - lib/jibbajabba.rb
84
+ - lib/jibbajabba/hip_chat.rb
85
+ - lib/jibbajabba/room.rb
86
+ - lib/jibbajabba/version.rb
87
+ - mrt.jpg
88
+ - spec/lib/jibbajabba/hip_chat_spec.rb
89
+ - spec/lib/jibbajabba/room_spec.rb
90
+ - spec/spec_helper.rb
91
+ homepage: https://github.com/NathanielWroblewski/jibbajabba
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.0.3
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Fluent Ruby API wrapper for the HipChat API
115
+ test_files:
116
+ - spec/lib/jibbajabba/hip_chat_spec.rb
117
+ - spec/lib/jibbajabba/room_spec.rb
118
+ - spec/spec_helper.rb