blimp 0.0.1

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.
data/.gitignore ADDED
@@ -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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in blimp.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Blake Williams
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.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # Blimp
2
+
3
+ Ruby gem that implements [Blimp's](http://www.getblimp.com/) public API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'blimp'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install blimp
18
+
19
+
20
+ ## Usage
21
+
22
+ Use the following template for your API credentials. If you don't have them already, you can get them [here](https://app.getblimp.com/user/settings/api/).
23
+
24
+ ```ruby
25
+ Blimp.api_key = "API_KEY"
26
+ Blimp.app_id = "APP_ID"
27
+ Blimp.app_secret = "APP_SECRET"
28
+ Blimp.username = "USERNAME"
29
+ ```
30
+
31
+ This gem implements Company, Project, Goal, Task, Comment, File, and User resources. There are two main methods for finding resources, first there is the `find` method that finds a single instance of a resource by its id. There is also a `find_all` method that returns an array of all of that resource.
32
+
33
+
34
+ ```ruby
35
+ project = Blimp::Project.find(1) # Finds a project with an id of 1
36
+ Blimp::Company.find_all # Finds all of the companies you have access to
37
+
38
+ project.name = "New Project Name" # Set the name of the project
39
+ project.save # Attempts to save the project's changes
40
+ ```
41
+
42
+
43
+ ## Todo
44
+
45
+ * Start testing the gem with Minitest
46
+ * Handle required fields when creating new resources
47
+ * Have better error coverage
48
+
49
+
50
+ ## Contributing
51
+
52
+ 1. Fork it
53
+ 3. Commit your changes
54
+ 4. Push to the your fork
55
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/blimp.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'blimp/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "blimp"
8
+ gem.version = Blimp::VERSION
9
+ gem.authors = ["Blake Williams"]
10
+ gem.email = ["blake@blakewilliams.me"]
11
+ gem.description = %q{Ruby gem that implements the Blimp Public API http://dev.getblimp.com/}
12
+ gem.summary = %q{Ruby bindings to the Blimp API}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ gem.add_dependency('httparty')
20
+ gem.add_dependency('active_support')
21
+ end
data/lib/blimp.rb ADDED
@@ -0,0 +1,18 @@
1
+ require "blimp/api"
2
+ require "blimp/resource"
3
+
4
+ require "blimp/company"
5
+ require "blimp/comment"
6
+ require "blimp/file"
7
+ require "blimp/goal"
8
+ require "blimp/task"
9
+ require "blimp/project"
10
+ require "blimp/user"
11
+
12
+ require "blimp/version"
13
+
14
+ module Blimp
15
+ class << self
16
+ attr_accessor :api_key, :app_secret, :app_id, :username
17
+ end
18
+ end
data/lib/blimp/api.rb ADDED
@@ -0,0 +1,45 @@
1
+ require 'httparty'
2
+
3
+ module Blimp
4
+ class API
5
+ class << self
6
+ @@base_uri = "https://app.getblimp.com/api/v2/"
7
+
8
+ def headers
9
+ @headers ||= { 'accept' => 'application/json',
10
+ 'content-type' => 'application/json',
11
+ 'Authorization' => "ApiKey #{Blimp.username}:#{Blimp.api_key}",
12
+ 'X_BLIMP_APPID' => Blimp.app_id,
13
+ 'X_BLIMP_SECRET' => Blimp.app_secret
14
+ }
15
+ end
16
+
17
+ def method_missing method_name, *args
18
+ super(method_name, args) unless [:get, :post, :put, :patch, :head, :destroy].include? method_name
19
+ uri = @@base_uri + args.shift
20
+
21
+ body = nil
22
+ body = args.shift[:body] if args.first.has_key? :body
23
+
24
+ query = nil
25
+ query = args.shift
26
+
27
+ HTTParty.send(method_name, uri, headers: headers, query: query, body: body)
28
+ end
29
+ end
30
+
31
+ class ResponseError < StandardError
32
+ end
33
+
34
+ class NotFound < ResponseError
35
+ end
36
+
37
+ class Forbidden < ResponseError
38
+ end
39
+
40
+ class InternalServerError < ResponseError
41
+ end
42
+
43
+ end
44
+ end
45
+
@@ -0,0 +1,9 @@
1
+ module Blimp
2
+ class Comment < Resource
3
+ ATTRIBUTES = %w[comment object_pk content_type]
4
+ READ_ONLY = %w[id files date_modified user date_created]
5
+
6
+ define_attribute_methods ATTRIBUTES, READ_ONLY
7
+ end
8
+ end
9
+
@@ -0,0 +1,8 @@
1
+ module Blimp
2
+ class Company < Resource
3
+ ATTRIBUTES = %w[name used_projects company_users image_url used_storage]
4
+ READ_ONLY = %w[id slug date_created date_modified date_due]
5
+
6
+ define_attribute_methods ATTRIBUTES, READ_ONLY
7
+ end
8
+ end
data/lib/blimp/file.rb ADDED
@@ -0,0 +1,9 @@
1
+ module Blimp
2
+ class File < Resource
3
+ ATTRIBUTES = %w[name versions project source]
4
+ READ_ONLY = %w[id slug date_created date_modified created_by]
5
+
6
+ define_attribute_methods ATTRIBUTES, READ_ONLY
7
+ end
8
+ end
9
+
data/lib/blimp/goal.rb ADDED
@@ -0,0 +1,10 @@
1
+ module Blimp
2
+ class Goal < Resource
3
+ ATTRIBUTES = %w[position date_rejected date_done user_rejected
4
+ title project state assigned_to]
5
+ READ_ONLY = %w[id date_modified created_by date_created]
6
+
7
+ define_attribute_methods ATTRIBUTES, READ_ONLY
8
+ end
9
+ end
10
+
@@ -0,0 +1,8 @@
1
+ module Blimp
2
+ class Project < Resource
3
+ ATTRIBUTES = %w[name state team date_due company]
4
+ READ_ONLY = %w[id slug date_created date_finished date_modified date_due stats]
5
+
6
+ define_attribute_methods ATTRIBUTES, READ_ONLY
7
+ end
8
+ end
@@ -0,0 +1,118 @@
1
+ require 'json'
2
+
3
+ module Blimp
4
+ class Resource
5
+ class << self
6
+
7
+ def find(id, options={})
8
+ uri = member_name
9
+ uri += "/#{id}" if id
10
+ parse_response API.get(uri, options)
11
+ end
12
+
13
+ def find_all(options={})
14
+ uri = member_name
15
+ parse_response API.get(uri, options), true
16
+ end
17
+
18
+ def parse_response(response, multiple=false)
19
+ case response.code.to_i
20
+ when 404
21
+ raise Blimp::API::NotFound.new(response), "Resource was not found"
22
+ when 403
23
+ raise Blimp::API::Forbidden.new(response), "Forbidden"
24
+ when 500
25
+ raise Blimp::API::InternalServerError.new(response), "500 Internal Server error. Make sure you're sending a proper request."
26
+ end
27
+
28
+ return build_record(response.parsed_response) unless multiple
29
+
30
+ resources = []
31
+ response.parsed_response['objects'].each do |project|
32
+ resources.push build_record(project)
33
+ end
34
+ return resources
35
+ end
36
+
37
+ def build_record(response)
38
+ attributes = {}
39
+ response.each_pair do |key, val|
40
+ attributes[key] = val if @attributes.include? key
41
+ end
42
+ new(attributes)
43
+ end
44
+
45
+ def member_name
46
+ name.split('::').last.downcase
47
+ end
48
+
49
+
50
+ def define_attribute_methods(attributes, read_only_attributes)
51
+ @attributes = attributes | read_only_attributes
52
+
53
+ @attributes.each do |name|
54
+ define_method(name) { self[name] }
55
+ define_method("#{name}?") {!self[name]}
56
+ define_method("#{name}=") {|val| self[name] = val} unless read_only_attributes.include?(name)
57
+ end
58
+ end
59
+
60
+ def define_readonly_attributes(attributes)
61
+ attributes.each do |name|
62
+ @attributes.push name
63
+ define_method(name) { self[name] }
64
+ define_method("#{name}?") {!self[name]}
65
+ end
66
+ end
67
+
68
+
69
+ def create attributes
70
+ new(attributes)
71
+ uri = "#{self.member_name}/"
72
+
73
+ parse_response Blimp::API.post(uri, body: attributes.to_json)
74
+ end
75
+
76
+ end
77
+ attr_accessor :attributes
78
+
79
+ def initialize attributes = {}
80
+ raise Error, "#{self.class} is an abstract class and cannot be instantiated" if instance_of? Resource
81
+
82
+ @attributes = {}
83
+ self.attributes = attributes
84
+ end
85
+
86
+ def []=(key,value)
87
+ @attributes[key] = value
88
+ end
89
+
90
+ def [](key)
91
+ @attributes[key]
92
+ end
93
+
94
+ def attributes=(attributes = {})
95
+ attributes.each_pair do |key, val|
96
+ self[key] = val
97
+ end
98
+ end
99
+
100
+ def new?
101
+ self.id?
102
+ end
103
+
104
+ def save
105
+ uri = "#{self.class.member_name}/"
106
+ uri += "#{self.id}/" unless self.new?
107
+
108
+ attributes = {}
109
+ @attributes.each_pair do |key,val|
110
+ next if self.class::READ_ONLY.include? key
111
+ attributes[key] = val
112
+ end
113
+ method = self.new? ? 'post' : 'put'
114
+ Blimp::API.send method, uri, body: attributes.to_json
115
+ end
116
+
117
+ end
118
+ end
data/lib/blimp/task.rb ADDED
@@ -0,0 +1,9 @@
1
+ module Blimp
2
+ class Task < Resource
3
+ ATTRIBUTES = %w[position goal user_rejected title project state assigned_to]
4
+ READ_ONLY = %w[id date_done date_modified created_by date_created
5
+ date_set_doing date_checked]
6
+
7
+ define_attribute_methods ATTRIBUTES, READ_ONLY
8
+ end
9
+ end
data/lib/blimp/user.rb ADDED
@@ -0,0 +1,8 @@
1
+ module Blimp
2
+ class User < Resource
3
+ ATTRIBUTES = %w[profile username first_name last_name email]
4
+ READ_ONLY = %w[]
5
+
6
+ define_attribute_methods ATTRIBUTES, READ_ONLY
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module Blimp
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blimp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Blake Williams
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: active_support
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Ruby gem that implements the Blimp Public API http://dev.getblimp.com/
47
+ email:
48
+ - blake@blakewilliams.me
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - blimp.gemspec
59
+ - lib/blimp.rb
60
+ - lib/blimp/api.rb
61
+ - lib/blimp/comment.rb
62
+ - lib/blimp/company.rb
63
+ - lib/blimp/file.rb
64
+ - lib/blimp/goal.rb
65
+ - lib/blimp/project.rb
66
+ - lib/blimp/resource.rb
67
+ - lib/blimp/task.rb
68
+ - lib/blimp/user.rb
69
+ - lib/blimp/version.rb
70
+ homepage: ''
71
+ licenses: []
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 1.8.23
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: Ruby bindings to the Blimp API
94
+ test_files: []
95
+ has_rdoc: