goplan 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Bradley Joyce
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.
@@ -0,0 +1,19 @@
1
+ = goplan
2
+
3
+ Ruby wrapper for the GoPlan API
4
+
5
+ https://goplanapp.com/api/docs
6
+
7
+ == Note on Patches/Pull Requests
8
+
9
+ * Fork the project.
10
+ * Make your feature addition or bug fix.
11
+ * Add tests for it. This is important so I don't break it in a
12
+ future version unintentionally.
13
+ * Commit, do not mess with rakefile, version, or history.
14
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
15
+ * Send me a pull request. Bonus points for topic branches.
16
+
17
+ == Copyright
18
+
19
+ Copyright (c) 2010 Bradley Joyce. See LICENSE for details.
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "goplan"
8
+ gem.summary = %Q{Ruby wrapper for the GoPlan API}
9
+ gem.description = %Q{Ruby wrapper for the GoPlan API}
10
+ gem.email = "brad@bradleyjoyce.com"
11
+ gem.homepage = "http://github.com/polomasta/goplan"
12
+ gem.authors = ["Bradley Joyce"]
13
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "goplan #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.4
@@ -0,0 +1,57 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{goplan}
8
+ s.version = "0.0.4"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Bradley Joyce"]
12
+ s.date = %q{2010-07-21}
13
+ s.description = %q{Ruby wrapper for the GoPlan API}
14
+ s.email = %q{brad@bradleyjoyce.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "goplan.gemspec",
27
+ "lib/go_plan/client.rb",
28
+ "lib/goplan.rb",
29
+ "test/helper.rb",
30
+ "test/oauth_test.rb",
31
+ "test/test_goplan.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/polomasta/goplan}
34
+ s.rdoc_options = ["--charset=UTF-8"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.3.6}
37
+ s.summary = %q{Ruby wrapper for the GoPlan API}
38
+ s.test_files = [
39
+ "test/helper.rb",
40
+ "test/oauth_test.rb",
41
+ "test/test_goplan.rb"
42
+ ]
43
+
44
+ if s.respond_to? :specification_version then
45
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
49
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
50
+ else
51
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
52
+ end
53
+ else
54
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
55
+ end
56
+ end
57
+
@@ -0,0 +1,76 @@
1
+ module GoPlan
2
+ class UnexpectedResponseError < RuntimeError
3
+ end
4
+
5
+ class Parser < HTTParty::Parser
6
+ def parse
7
+ begin
8
+ Crack::JSON.parse(body)
9
+ rescue => e
10
+ raise UnexpectedResponseError, "Crack could not parse JSON. It said: #{e.message}. GoPlan's raw response: #{body}"
11
+ end
12
+ end
13
+ end
14
+
15
+ class Client
16
+ include HTTParty
17
+
18
+ parser GoPlan::Parser
19
+ headers 'Content-Type' => 'application/json'
20
+
21
+ attr_reader :ctoken, :csecret, :consumer_options, :company_alias
22
+
23
+ def initialize(ctoken=GoPlan.token, csecret=GoPlan.secret, company_alias, options={})
24
+ opts = {
25
+ #:request_token_path => "/uas/oauth/requestToken",
26
+ #:access_token_path => "/uas/oauth/accessToken",
27
+ :authorize_path => "/oauth/authorize"
28
+ }
29
+ @ctoken, @csecret, @consumer_options = ctoken, csecret, opts.merge(options)
30
+ @company_alias = company_alias
31
+ self.class.base_uri "http://#{@company_alias}.goplanapp.com"
32
+ end
33
+
34
+ def consumer
35
+ @consumer ||= ::OAuth::Consumer.new(@ctoken, @csecret, {:site => 'http://www.goplanapp.com'}.merge(consumer_options))
36
+ end
37
+
38
+ def set_callback_url(url)
39
+ clear_request_token
40
+ request_token(:oauth_callback => url)
41
+ end
42
+
43
+ # Note: If using oauth with a web app, be sure to provide :oauth_callback.
44
+ # Options:
45
+ # :oauth_callback => String, url that LinkedIn should redirect to
46
+ def request_token(options={})
47
+ @request_token ||= consumer.get_request_token(options)
48
+ end
49
+
50
+ # For web apps use params[:oauth_verifier], for desktop apps,
51
+ # use the verifier is the pin that LinkedIn gives users.
52
+ def authorize_from_request(rtoken, rsecret, verifier_or_pin)
53
+ request_token = ::OAuth::RequestToken.new(consumer, rtoken, rsecret)
54
+ access_token = request_token.get_access_token(:oauth_verifier => verifier_or_pin)
55
+ @atoken, @asecret = access_token.token, access_token.secret
56
+ end
57
+
58
+ def access_token
59
+ @access_token ||= ::OAuth::AccessToken.new(consumer, @atoken, @asecret)
60
+ end
61
+
62
+ def authorize_from_access(atoken, asecret)
63
+ @atoken, @asecret = atoken, asecret
64
+ end
65
+
66
+ #options:
67
+ # id => number of items to return, defaults to 100
68
+ # project => project alias (alias of a specific project) - not mandatory, defaults to company scope
69
+
70
+ def activiy(options={})
71
+ activities = get("/activites/get_all.json", :query => options)
72
+ acitivities.map{|a| Hashie::Mash.new c['activity']}
73
+ end
74
+ end
75
+
76
+ end
@@ -0,0 +1,60 @@
1
+ require 'rubygems'
2
+
3
+ gem 'oauth'
4
+ require 'oauth'
5
+
6
+ gem 'crack', '~> 0.1.4'
7
+ require 'crack'
8
+
9
+ require 'hashie'
10
+ require 'httparty'
11
+ require 'json'
12
+
13
+ require 'cgi'
14
+
15
+ module GoPlan
16
+ class GoPlanError < StandardError
17
+ attr_reader :data
18
+
19
+ def initialize(data)
20
+ @data = data
21
+ super
22
+ end
23
+ end
24
+
25
+ class RateLimitExceeded < GoPlanError; end
26
+ class Unauthorized < GoPlanError; end
27
+ class General < GoPlanError; end
28
+
29
+ class Unavailable < StandardError; end
30
+ class InformGoPlan < StandardError; end
31
+ class NotFound < StandardError; end
32
+
33
+ def self.configure
34
+ yield self
35
+
36
+ GoPlan.token = token
37
+ GoPlan.secret = secret
38
+ true
39
+ end
40
+
41
+ def self.token
42
+ @token
43
+ end
44
+
45
+ def self.token=(token)
46
+ @token = token
47
+ end
48
+
49
+ def self.secret
50
+ @secret
51
+ end
52
+
53
+ def self.secret=(secret)
54
+ @secret = secret
55
+ end
56
+ end
57
+
58
+ directory = File.expand_path(File.dirname(__FILE__))
59
+
60
+ require File.join(directory, 'go_plan', 'client')
@@ -0,0 +1,51 @@
1
+ require 'test/unit'
2
+ require 'pathname'
3
+ require 'rubygems'
4
+
5
+ gem 'thoughtbot-shoulda', '>= 2.10.1'
6
+ gem 'jnunemaker-matchy', '>=0.4.0'
7
+ gem 'mocha', '>=0.9.4'
8
+ gem 'fakeweb', '>= 1.2.5'
9
+
10
+ require 'shoulda'
11
+ require 'matchy'
12
+ require 'mocha'
13
+ require 'fakeweb'
14
+
15
+ FakeWeb.allow_net_connect = false
16
+
17
+ dir = (Pathname(__FILE__).dirname + '../lib').expand_path
18
+ require dir + 'goplan'
19
+
20
+ class Test::Unit::TestCase
21
+ end
22
+
23
+ def fixture_file(filename)
24
+ return '' if filename == ''
25
+ file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
26
+ File.read(file_path)
27
+ end
28
+
29
+ def goplan_url(url)
30
+ url =~ /^http/ ? url : "http://velocis.goplan.com#{url}"
31
+ end
32
+
33
+ def stub_get(url, filename, status=nil)
34
+ options = {:body => fixture_file(filename)}
35
+ options.merge!({:status => status}) unless status.nil?
36
+
37
+ FakeWeb.register_uri(:get, goplan_url(url), options)
38
+ end
39
+
40
+ def stub_post(url, filename)
41
+ FakeWeb.register_uri(:post, goplan_url(url), :body => fixture_file(filename))
42
+ end
43
+
44
+ def stub_put(url, filename)
45
+ FakeWeb.register_uri(:put, goplan_url(url), :body => fixture_file(filename))
46
+ end
47
+
48
+ def stub_delete(url, filename)
49
+ FakeWeb.register_uri(:delete, goplan_url(url), :body => fixture_file(filename))
50
+
51
+ end
@@ -0,0 +1,117 @@
1
+ require 'helper'
2
+
3
+ class OAuthTest < Test::Unit::TestCase
4
+ should "initialize with consumer token and secret" do
5
+ goplan = GoPlan::Client.new('token', 'secret')
6
+
7
+ goplan.ctoken.should == 'token'
8
+ goplan.csecret.should == 'secret'
9
+ end
10
+
11
+ should "set authorization path to '/oauth/authorize' by default" do
12
+ goplan = GoPlan::Client.new('token', 'secret')
13
+ goplan.consumer.options[:authorize_path].should == '/oauth/authorize'
14
+ end
15
+
16
+ should "have a consumer" do
17
+ consumer = mock('oauth consumer')
18
+ options = {
19
+ #:request_token_path => "/uas/oauth/requestToken",
20
+ #:access_token_path => "/uas/oauth/accessToken",
21
+ :authorize_path => "/uas/oauth/authorize",
22
+ :site => 'http://www.goplanapp.com'
23
+ }
24
+ OAuth::Consumer.expects(:new).with('token', 'secret', options).returns(consumer)
25
+ goplan = GoPlan::Client.new('token', 'secret')
26
+
27
+ goplan.consumer.should == consumer
28
+ end
29
+
30
+ should "have a request token from the consumer" do
31
+ options = {
32
+ #:request_token_path => "/uas/oauth/requestToken",
33
+ #:access_token_path => "/uas/oauth/accessToken",
34
+ :authorize_path => "/oauth/authorize",
35
+ :site => 'http://www.goplanapp.com'
36
+ }
37
+ consumer = mock('oauth consumer')
38
+ request_token = mock('request token')
39
+ consumer.expects(:get_request_token).returns(request_token)
40
+ OAuth::Consumer.expects(:new).with('token', 'secret', options).returns(consumer)
41
+ goplan = GoPlan::Client.new('token', 'secret')
42
+
43
+ goplan.request_token.should == request_token
44
+ end
45
+
46
+ context "set_callback_url" do
47
+ should "clear request token and set the callback url" do
48
+ consumer = mock('oauth consumer')
49
+ request_token = mock('request token')
50
+ options = {
51
+ #:request_token_path => "/uas/oauth/requestToken",
52
+ #:access_token_path => "/uas/oauth/accessToken",
53
+ :authorize_path => "/oauth/authorize",
54
+ :site => 'http://www.goplanapp.com'
55
+ }
56
+ OAuth::Consumer.
57
+ expects(:new).
58
+ with('token', 'secret', options).
59
+ returns(consumer)
60
+
61
+ goplan = GoPlan::Client.new('token', 'secret')
62
+
63
+ consumer.
64
+ expects(:get_request_token).
65
+ with({:oauth_callback => 'http://myapp.goplanapp.com/oauth_callback'})
66
+
67
+ goplan.set_callback_url('http://myapp.goplanapp.com/oauth_callback')
68
+ end
69
+ end
70
+
71
+ should "be able to create access token from request token, request secret and verifier" do
72
+ goplan = GoPplan::Client.new('token', 'secret')
73
+ consumer = OAuth::Consumer.new('token', 'secret', {:site => 'http://www.goplanapp.com'})
74
+ goplan.stubs(:consumer).returns(consumer)
75
+
76
+ access_token = mock('access token', :token => 'atoken', :secret => 'asecret')
77
+ request_token = mock('request token')
78
+ request_token.
79
+ expects(:get_access_token).
80
+ with(:oauth_verifier => 'verifier').
81
+ returns(access_token)
82
+
83
+ OAuth::RequestToken.
84
+ expects(:new).
85
+ with(consumer, 'rtoken', 'rsecret').
86
+ returns(request_token)
87
+
88
+ goplan.authorize_from_request('rtoken', 'rsecret', 'verifier')
89
+ goplan.access_token.class.should be(OAuth::AccessToken)
90
+ goplan.access_token.token.should == 'atoken'
91
+ goplan.access_token.secret.should == 'asecret'
92
+ end
93
+
94
+ should "be able to create access token from access token and secret" do
95
+ goplan = GoPlan::Client.new('token', 'secret')
96
+ consumer = OAuth::Consumer.new('token', 'secret', {:site => 'http://www.goplanapp.com'})
97
+ goplan.stubs(:consumer).returns(consumer)
98
+
99
+ goplan.authorize_from_access('atoken', 'asecret')
100
+ goplan.access_token.class.should be(OAuth::AccessToken)
101
+ goplan.access_token.token.should == 'atoken'
102
+ goplan.access_token.secret.should == 'asecret'
103
+ end
104
+
105
+ should "be able to configure consumer token and consumer secret without passing to initialize" do
106
+ GoPlan.configure do |config|
107
+ config.token = 'consumer_token'
108
+ config.secret = 'consumer_secret'
109
+ end
110
+
111
+ goplan = GoPlan::Client.new
112
+ goplan.ctoken.should == 'consumer_token'
113
+ goplan.csecret.should == 'consumer_secret'
114
+ end
115
+
116
+
117
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestGoplan < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ assert = true
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: goplan
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 4
9
+ version: 0.0.4
10
+ platform: ruby
11
+ authors:
12
+ - Bradley Joyce
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-07-21 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: thoughtbot-shoulda
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :development
31
+ version_requirements: *id001
32
+ description: Ruby wrapper for the GoPlan API
33
+ email: brad@bradleyjoyce.com
34
+ executables: []
35
+
36
+ extensions: []
37
+
38
+ extra_rdoc_files:
39
+ - LICENSE
40
+ - README.rdoc
41
+ files:
42
+ - .document
43
+ - .gitignore
44
+ - LICENSE
45
+ - README.rdoc
46
+ - Rakefile
47
+ - VERSION
48
+ - goplan.gemspec
49
+ - lib/go_plan/client.rb
50
+ - lib/goplan.rb
51
+ - test/helper.rb
52
+ - test/oauth_test.rb
53
+ - test/test_goplan.rb
54
+ has_rdoc: true
55
+ homepage: http://github.com/polomasta/goplan
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options:
60
+ - --charset=UTF-8
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ requirements: []
78
+
79
+ rubyforge_project:
80
+ rubygems_version: 1.3.6
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Ruby wrapper for the GoPlan API
84
+ test_files:
85
+ - test/helper.rb
86
+ - test/oauth_test.rb
87
+ - test/test_goplan.rb