gluestick 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/LICENSE +22 -0
  2. data/README +7 -0
  3. data/README.markdown +34 -0
  4. data/Rakefile +28 -0
  5. data/VERSION +1 -0
  6. data/lib/gluestick.rb +56 -0
  7. metadata +72 -0
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2009 Justin Poliey <jdp34@njit.edu>
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,7 @@
1
+ Call methods simply,
2
+ You already know their names,
3
+ No need to worry.
4
+
5
+ Gluestick is a minimalist approach to the
6
+ Glue API. It is primarily a Ruby Gem, but a
7
+ PHP version exists as well.
data/README.markdown ADDED
@@ -0,0 +1,34 @@
1
+ # Gluestick
2
+
3
+ Gluestick is a simple interface to the Glue API for Ruby.
4
+ Rather than learning a new set of methods, you just use Glue's native methods.
5
+
6
+ ## Get your construction paper out: A Tutorial
7
+
8
+ To get started, include the **gluestick** gem and instantiate a Glue class.
9
+ Every method in the Glue API requires authentication, so you'll also need to use a valid username and password.
10
+
11
+ require 'rubygems'
12
+ require 'gluestick'
13
+ glue = Glue.new
14
+ response = glue.user.login({:userId => 'userid', :password => 'password'})
15
+
16
+ To actually use methods, call the same ones you would as if you were calling them right through HTTP.
17
+ If you wanted to use the `user/friends` method, you would do this:
18
+
19
+ friends = glue.user.friends(:userId => 'jdp')
20
+
21
+ See the correspondence? `glue.user.friends` maps itself to `http://api.getglue.com/v2/user/friends`.
22
+
23
+ Query string parameters are passed through a hash as the first argument. **That's all you need to know.**
24
+
25
+ ## About
26
+
27
+ 2009 [Justin Poliey](http://justinpoliey.com)
28
+
29
+ 2010 [HeresTomWithTheWeather](http://www.opensourcecurrency.org) - updated gem for V2
30
+
31
+ ## PHP Version
32
+
33
+ Gluestick is also available as a PHP library.
34
+ It is available in the 'php' branch, or you can just follow [this link](http://github.com/jdp/gluestick/tree/php).
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+
5
+ begin
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |gemspec|
8
+ gemspec.name = "gluestick"
9
+ gemspec.summary = "A simple interface to the Glue API"
10
+ gemspec.email = "herestomwiththeweather@gmail.com"
11
+ gemspec.homepage = "http://github.com/herestomwiththeweather/gluestick"
12
+ gemspec.description = "A simple interface to the Glue API"
13
+ gemspec.authors = ["Justin Poliey","HeresTomWithTheWeather"]
14
+ gemspec.add_dependency "httparty", ">= 0.4.3"
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+
18
+ rescue LoadError
19
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
20
+ end
21
+
22
+ desc "Run basic tests"
23
+ Rake::TestTask.new("test") do |t|
24
+ t.pattern = "test/*_test.rb"
25
+ t.verbose = true
26
+ # HTTParty generates tons of warnings
27
+ t.warning = false
28
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.3.0
data/lib/gluestick.rb ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'httparty'
3
+
4
+ class GlueError < RuntimeError
5
+ attr_reader :message
6
+ def initialize message
7
+ @message = message
8
+ end
9
+ end
10
+
11
+ class Glue
12
+ include HTTParty
13
+ base_uri 'api.getglue.com'
14
+
15
+ attr_reader :glue_token
16
+
17
+ GLUE_API_VERSION = '4.5'
18
+
19
+ def initialize()
20
+ @method_family = nil
21
+ @glue_token = ""
22
+ end
23
+
24
+ def method_missing(name, *args)
25
+ if @method_family == nil
26
+ # The first missing_method is the first part of the method
27
+ @method_family = name
28
+ # Return self to chain a second method_missing
29
+ self
30
+ else
31
+ # The second missing_method is the second part of the method
32
+ # The current API format is "/v1/part_a/part_b?params"
33
+ method = "/v2/%s/%s" % [@method_family.to_s, name.to_s]
34
+ @method_family = nil
35
+ # Build HTTParty options from a hash and provide auth
36
+ glue_params = {:version => GLUE_API_VERSION}
37
+ glue_params.merge!({:token => @glue_token}) unless @glue_token.empty?
38
+ glue_params.merge!(args[0]) unless args[0].nil?
39
+ options = {:query => glue_params}
40
+ begin
41
+ response = self.class.get(method, options)
42
+ rescue SocketError => desc
43
+ raise GlueError.new("Could not connect")
44
+ end
45
+ # A couple convenience exceptions
46
+ raise GlueError.new("401 Unauthorized") if response.code == 401
47
+ raise GlueError.new("404 Not Found") if response.code == 404
48
+ raise GlueError.new("Invalid request") unless (200..299) === response.code
49
+ # Return the response as a hash, thanks to crack
50
+ if '/v2/user/login' == method
51
+ @glue_token = response['adaptiveblue']['response']['ping']['token']
52
+ end
53
+ response
54
+ end
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gluestick
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Justin Poliey
8
+ - HeresTomWithTheWeather
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2010-02-21 00:00:00 -06:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: httparty
18
+ type: :runtime
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 0.4.3
25
+ version:
26
+ description: A simple interface to the Glue API
27
+ email: herestomwiththeweather@gmail.com
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - LICENSE
34
+ - README
35
+ - README.markdown
36
+ files:
37
+ - LICENSE
38
+ - README
39
+ - README.markdown
40
+ - Rakefile
41
+ - VERSION
42
+ - lib/gluestick.rb
43
+ has_rdoc: true
44
+ homepage: http://github.com/herestomwiththeweather/gluestick
45
+ licenses: []
46
+
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --charset=UTF-8
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.3.5
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: A simple interface to the Glue API
71
+ test_files: []
72
+