sifterology 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "httparty", "~>0.6.1"
4
+ gem "json", "~>1.4.6"
5
+
6
+ group :development do
7
+ gem 'jeweler'
8
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,21 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ crack (0.1.8)
5
+ git (1.2.5)
6
+ httparty (0.6.1)
7
+ crack (= 0.1.8)
8
+ jeweler (1.5.2)
9
+ bundler (~> 1.0.0)
10
+ git (>= 1.2.5)
11
+ rake
12
+ json (1.4.6)
13
+ rake (0.8.7)
14
+
15
+ PLATFORMS
16
+ ruby
17
+
18
+ DEPENDENCIES
19
+ httparty (~> 0.6.1)
20
+ jeweler
21
+ json (~> 1.4.6)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Ilya Sabanin
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.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = sifterology
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to sifterology
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Ilya Sabanin. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts "Run `bundle install` to install missing gems"
9
+ exit e.status_code
10
+ end
11
+
12
+ require 'jeweler'
13
+ require 'rake'
14
+
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "sifterology"
18
+ gem.homepage = "http://github.com/iSabanin/sifterology"
19
+ gem.license = "MIT"
20
+ gem.summary = "Quick and dirty API wrapper for Sifter app."
21
+ gem.description = "Yeah, that's true."
22
+ gem.email = "ilya.sabanin@gmail.com"
23
+ gem.authors = ["Ilya Sabanin"]
24
+ gem.add_dependency "httparty", ">= 0.6.1"
25
+ gem.add_dependency "json", ">= 1.4.6"
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ task :default => :test
37
+
38
+ require 'rake/rdoctask'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "sifterology #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,26 @@
1
+ require 'httparty'
2
+ require 'json'
3
+
4
+ module Sifterology
5
+
6
+ VERSION = '0.1.1'
7
+
8
+ def self.session(account_url, token, options={})
9
+ Session.new(account_url, token, options)
10
+ end
11
+
12
+ end
13
+
14
+ def require_local(suffix)
15
+ require(File.expand_path(File.join(File.dirname(__FILE__), suffix)))
16
+ end
17
+
18
+ require_local "sifterology/errors"
19
+ require_local "sifterology/error_translator"
20
+ require_local "sifterology/request"
21
+ require_local "sifterology/resource"
22
+ require_local "sifterology/session"
23
+ require_local "sifterology/project"
24
+ require_local "sifterology/commit"
25
+ require_local "sifterology/factories/project_factory"
26
+ require_local "sifterology/factories/commit_factory"
@@ -0,0 +1,47 @@
1
+ module Sifterology
2
+
3
+ class Commit < Resource
4
+
5
+ attr_accessor :project_url, :status, :assignee, :unassign, :issue, :changeset_url,
6
+ :committer, :committer_email, :commit_time, :commit_message
7
+
8
+ def save
9
+ post(entity_path, :body => payload)
10
+ end
11
+
12
+ def entity_path
13
+ File.join(project_path, 'beanstalk')
14
+ end
15
+
16
+ def project_path
17
+ URI.parse(project_url).path
18
+ end
19
+
20
+ private
21
+
22
+ def payload
23
+ sanitize_payload({
24
+ "issue" => issue,
25
+ "assignee" => assignee,
26
+ "status" => status,
27
+ "commit" => {
28
+ "changeset_url" => changeset_url,
29
+ "message" => commit_message,
30
+ "author" => committer,
31
+ "author_email" => committer_email,
32
+ "time" => commit_time,
33
+ }
34
+ })
35
+ end
36
+
37
+ def sanitize_payload(hash)
38
+ hash.tap do |h|
39
+ h['assignee'] = '' if unassign
40
+ h.delete("status") if hash["status"].nil?
41
+ h.delete("assignee") if hash["assignee"].nil?
42
+ end
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -0,0 +1,22 @@
1
+ module Sifterology
2
+
3
+ module ErrorTranslator
4
+
5
+ extend self
6
+
7
+ def translate_to_exception(sifter_message)
8
+ case sifter_message
9
+ when /Secure Connection Required/i
10
+ return SSLRequired.new(sifter_message)
11
+ when /Invalid Token/i
12
+ return InvalidToken.new(sifter_message)
13
+ when /Invalid Account/i
14
+ return InvalidAccount.new(sifter_message)
15
+ end
16
+
17
+ SifterError.new(sifter_message)
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,21 @@
1
+ module Sifterology
2
+
3
+ class SifterError < Exception
4
+
5
+ def initialize(msg=nil)
6
+ @message = msg
7
+ end
8
+
9
+ def to_s
10
+ @message
11
+ end
12
+
13
+ end
14
+
15
+ class SSLRequired < SifterError; end
16
+
17
+ class InvalidToken < SifterError; end
18
+
19
+ class InvalidAccount < SifterError; end
20
+
21
+ end
@@ -0,0 +1,17 @@
1
+ module Sifterology
2
+
3
+ class CommitFactory < Resource
4
+
5
+ def create(attrs={})
6
+ build(attrs).save
7
+ end
8
+
9
+ def build(attrs={})
10
+ commit = Commit.new(session, self)
11
+ commit.local_attributes = attrs
12
+ commit
13
+ end
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,31 @@
1
+ module Sifterology
2
+
3
+ class ProjectFactory < Resource
4
+
5
+ def entity_base
6
+ '/api/projects'
7
+ end
8
+
9
+ def find_all
10
+ [].tap do |arr|
11
+ get("#{ entity_base }/?all=true")['projects'].each do |project_attrs|
12
+ arr << build(project_attrs)
13
+ end
14
+ end
15
+ end
16
+
17
+ def build(attributes)
18
+ Project.new(session, self).tap do |p|
19
+ p.attributes = attributes
20
+ end
21
+ end
22
+
23
+ def new_from_url(url)
24
+ Project.new(session, self).tap do |p|
25
+ p.api_url = url
26
+ end
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,24 @@
1
+ require 'open-uri'
2
+
3
+ module Sifterology
4
+
5
+ class Project < Resource
6
+
7
+ sifter_attrs :name, :api_url, :issues_url, :archived, :primary_company_name
8
+
9
+ def archived?
10
+ archived
11
+ end
12
+
13
+ def api_path
14
+ URI.parse(api_url).path
15
+ end
16
+
17
+ def test_request
18
+ response = post(File.join(api_path, 'beanstalk', 'test'), :body => '')
19
+ response && response["summary"] == 'Success'
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,65 @@
1
+ module Sifterology
2
+
3
+ class Request
4
+
5
+ include HTTParty
6
+
7
+ #debug_output $stdout
8
+
9
+ attr_reader :resource, :response
10
+
11
+ def initialize(resource)
12
+ @resource = resource
13
+ end
14
+
15
+ def perform(*args)
16
+ method, path, options = args.shift, args.shift, args.last
17
+ url = File.join(resource.session.account_url, path)
18
+ options ||= {}
19
+ prepare_options(options)
20
+ process_response(self.class.send(method, url, options))
21
+ end
22
+
23
+ private
24
+
25
+ def setup_headers
26
+ Hash.new.tap do |h|
27
+ h['X-Sifter-Token'] = resource.session.token
28
+ h['Content-Type'] = 'application/json'
29
+ h['Accept'] = 'application/json'
30
+ h['X-Partner-Token'] = resource.session.partner_token if resource.session.partner_token
31
+ end
32
+ end
33
+
34
+ def prepare_options(options)
35
+ options[:headers] = setup_headers
36
+ options[:body] = options[:body].to_json if options[:body].kind_of?(Hash)
37
+ end
38
+
39
+ def process_response(response)
40
+ memorize_response_data(response)
41
+ if response.code == 200
42
+ if response.respond_to?(:parsed_response)
43
+ response.parsed_response
44
+ else
45
+ response
46
+ end
47
+ else
48
+ convert_sifter_messages_to_exceptions(response['error'] || response['detail'])
49
+ response
50
+ end
51
+ end
52
+
53
+ def convert_sifter_messages_to_exceptions(messages)
54
+ [messages].each do |msg|
55
+ raise ErrorTranslator.translate_to_exception(msg)
56
+ end
57
+ end
58
+
59
+ def memorize_response_data(response)
60
+ @response = response
61
+ end
62
+
63
+ end
64
+
65
+ end
@@ -0,0 +1,62 @@
1
+ module Sifterology
2
+
3
+ class Resource
4
+
5
+ attr_reader :session, :factory
6
+ attr_accessor :last_request
7
+
8
+ def self.sifter_attrs(*args)
9
+ args.each do |name|
10
+ define_method(name) do
11
+ instance_variable_get("@_sifter_#{name}")
12
+ end
13
+
14
+ define_method("#{name}=") do |value|
15
+ instance_variable_set("@_sifter_#{name}", value)
16
+ end
17
+ end
18
+ end
19
+
20
+ def initialize(session, factory=nil)
21
+ @session = session
22
+ @factory = factory
23
+ end
24
+
25
+ def get(*args)
26
+ request(:get, *args)
27
+ end
28
+
29
+ def post(*args)
30
+ request(:post, *args)
31
+ end
32
+
33
+ def put(*args)
34
+ request(:put, *args)
35
+ end
36
+
37
+ def delete(*args)
38
+ request(:delete, *args)
39
+ end
40
+
41
+ def attributes=(hash)
42
+ hash.each_pair do |name, value|
43
+ instance_variable_set("@_sifter_#{ name }", value)
44
+ end
45
+ end
46
+
47
+ def local_attributes=(hash)
48
+ hash.each_pair do |name, value|
49
+ instance_variable_set("@#{ name }", value)
50
+ end
51
+ end
52
+
53
+ private
54
+
55
+ def request(*args)
56
+ @last_request = Request.new(self)
57
+ @last_request.perform(*args)
58
+ end
59
+
60
+ end
61
+
62
+ end
@@ -0,0 +1,23 @@
1
+ module Sifterology
2
+
3
+ class Session
4
+
5
+ attr_reader :account_url, :token, :partner_token
6
+
7
+ def initialize(account_url, token, options={})
8
+ @account_url = account_url
9
+ @token = token
10
+ @partner_token = options[:partner_token]
11
+ end
12
+
13
+ def projects
14
+ ProjectFactory.new(self)
15
+ end
16
+
17
+ def commits
18
+ CommitFactory.new(self)
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,75 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{sifterology}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Ilya Sabanin"]
12
+ s.date = %q{2011-03-11}
13
+ s.description = %q{Yeah, that's true.}
14
+ s.email = %q{ilya.sabanin@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/sifterology.rb",
28
+ "lib/sifterology/commit.rb",
29
+ "lib/sifterology/error_translator.rb",
30
+ "lib/sifterology/errors.rb",
31
+ "lib/sifterology/factories/commit_factory.rb",
32
+ "lib/sifterology/factories/project_factory.rb",
33
+ "lib/sifterology/project.rb",
34
+ "lib/sifterology/request.rb",
35
+ "lib/sifterology/resource.rb",
36
+ "lib/sifterology/session.rb",
37
+ "sifterology.gemspec",
38
+ "test/helper.rb",
39
+ "test/test_sifterology.rb"
40
+ ]
41
+ s.homepage = %q{http://github.com/iSabanin/sifterology}
42
+ s.licenses = ["MIT"]
43
+ s.require_paths = ["lib"]
44
+ s.rubygems_version = %q{1.6.2}
45
+ s.summary = %q{Quick and dirty API wrapper for Sifter app.}
46
+ s.test_files = [
47
+ "test/helper.rb",
48
+ "test/test_sifterology.rb"
49
+ ]
50
+
51
+ if s.respond_to? :specification_version then
52
+ s.specification_version = 3
53
+
54
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
+ s.add_runtime_dependency(%q<httparty>, ["~> 0.6.1"])
56
+ s.add_runtime_dependency(%q<json>, ["~> 1.4.6"])
57
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
58
+ s.add_runtime_dependency(%q<httparty>, [">= 0.6.1"])
59
+ s.add_runtime_dependency(%q<json>, [">= 1.4.6"])
60
+ else
61
+ s.add_dependency(%q<httparty>, ["~> 0.6.1"])
62
+ s.add_dependency(%q<json>, ["~> 1.4.6"])
63
+ s.add_dependency(%q<jeweler>, [">= 0"])
64
+ s.add_dependency(%q<httparty>, [">= 0.6.1"])
65
+ s.add_dependency(%q<json>, [">= 1.4.6"])
66
+ end
67
+ else
68
+ s.add_dependency(%q<httparty>, ["~> 0.6.1"])
69
+ s.add_dependency(%q<json>, ["~> 1.4.6"])
70
+ s.add_dependency(%q<jeweler>, [">= 0"])
71
+ s.add_dependency(%q<httparty>, [">= 0.6.1"])
72
+ s.add_dependency(%q<json>, [">= 1.4.6"])
73
+ end
74
+ end
75
+
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'sifterology'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestSifterology < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sifterology
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - Ilya Sabanin
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-11 00:00:00 +07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ prerelease: false
23
+ type: :runtime
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 5
30
+ segments:
31
+ - 0
32
+ - 6
33
+ - 1
34
+ version: 0.6.1
35
+ name: httparty
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ prerelease: false
39
+ type: :runtime
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 11
46
+ segments:
47
+ - 1
48
+ - 4
49
+ - 6
50
+ version: 1.4.6
51
+ name: json
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ prerelease: false
55
+ type: :development
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ name: jeweler
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ prerelease: false
69
+ type: :runtime
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 5
76
+ segments:
77
+ - 0
78
+ - 6
79
+ - 1
80
+ version: 0.6.1
81
+ name: httparty
82
+ version_requirements: *id004
83
+ - !ruby/object:Gem::Dependency
84
+ prerelease: false
85
+ type: :runtime
86
+ requirement: &id005 !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ hash: 11
92
+ segments:
93
+ - 1
94
+ - 4
95
+ - 6
96
+ version: 1.4.6
97
+ name: json
98
+ version_requirements: *id005
99
+ description: Yeah, that's true.
100
+ email: ilya.sabanin@gmail.com
101
+ executables: []
102
+
103
+ extensions: []
104
+
105
+ extra_rdoc_files:
106
+ - LICENSE.txt
107
+ - README.rdoc
108
+ files:
109
+ - .document
110
+ - Gemfile
111
+ - Gemfile.lock
112
+ - LICENSE.txt
113
+ - README.rdoc
114
+ - Rakefile
115
+ - VERSION
116
+ - lib/sifterology.rb
117
+ - lib/sifterology/commit.rb
118
+ - lib/sifterology/error_translator.rb
119
+ - lib/sifterology/errors.rb
120
+ - lib/sifterology/factories/commit_factory.rb
121
+ - lib/sifterology/factories/project_factory.rb
122
+ - lib/sifterology/project.rb
123
+ - lib/sifterology/request.rb
124
+ - lib/sifterology/resource.rb
125
+ - lib/sifterology/session.rb
126
+ - sifterology.gemspec
127
+ - test/helper.rb
128
+ - test/test_sifterology.rb
129
+ has_rdoc: true
130
+ homepage: http://github.com/iSabanin/sifterology
131
+ licenses:
132
+ - MIT
133
+ post_install_message:
134
+ rdoc_options: []
135
+
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ hash: 3
144
+ segments:
145
+ - 0
146
+ version: "0"
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ none: false
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ hash: 3
153
+ segments:
154
+ - 0
155
+ version: "0"
156
+ requirements: []
157
+
158
+ rubyforge_project:
159
+ rubygems_version: 1.6.2
160
+ signing_key:
161
+ specification_version: 3
162
+ summary: Quick and dirty API wrapper for Sifter app.
163
+ test_files:
164
+ - test/helper.rb
165
+ - test/test_sifterology.rb