freckly 0.0.0

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) 2009 reddavis
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,17 @@
1
+ = Freckly
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (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)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Red Davis. See LICENSE for details.
@@ -0,0 +1,31 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "freckly"
8
+ gem.summary = %Q{Freckle Gem}
9
+ gem.description = %Q{Freckle Gem}
10
+ gem.email = "reddavis@gmail.com"
11
+ gem.homepage = "http://github.com/reddavis/freckly"
12
+ gem.authors = ["reddavis"]
13
+ gem.add_development_dependency("rspec", "~> 1.3.0")
14
+ gem.add_runtime_dependency("faraday", "~> 0.4.6")
15
+ gem.add_runtime_dependency("faraday_middleware", "~> 0.1.0")
16
+ gem.add_runtime_dependency("multi_xml", "~> 0.0.1")
17
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
+ end
19
+ Jeweler::GemcutterTasks.new
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
+ end
23
+
24
+ require 'spec/rake/spectask'
25
+ Spec::Rake::SpecTask.new do |t|
26
+ t.ruby_opts = ["-I spec/", "-rubygems"]
27
+ puts FileList['spec/**/*_spec.rb'].inspect
28
+ t.spec_files = FileList['spec/**/*_spec.rb']
29
+ end
30
+
31
+ task :default => :spec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,73 @@
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{freckly}
8
+ s.version = "0.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["reddavis"]
12
+ s.date = %q{2010-10-04}
13
+ s.description = %q{Freckle Gem}
14
+ s.email = %q{reddavis@gmail.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
+ "freckly.gemspec",
27
+ "lib/freckly.rb",
28
+ "lib/freckly/entry.rb",
29
+ "lib/freckly/faraday/parse_xml.rb",
30
+ "lib/freckly/project.rb",
31
+ "spec/fixtures/entries.xml",
32
+ "spec/fixtures/projects.xml",
33
+ "spec/freckly/entry_spec.rb",
34
+ "spec/freckly/project_spec.rb",
35
+ "spec/freckly_spec.rb",
36
+ "spec/spec.opts",
37
+ "spec/spec_helper.rb"
38
+ ]
39
+ s.homepage = %q{http://github.com/reddavis/freckly}
40
+ s.rdoc_options = ["--charset=UTF-8"]
41
+ s.require_paths = ["lib"]
42
+ s.rubygems_version = %q{1.3.6}
43
+ s.summary = %q{Freckle Gem}
44
+ s.test_files = [
45
+ "spec/freckly/entry_spec.rb",
46
+ "spec/freckly/project_spec.rb",
47
+ "spec/freckly_spec.rb",
48
+ "spec/spec_helper.rb"
49
+ ]
50
+
51
+ if s.respond_to? :specification_version then
52
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
53
+ s.specification_version = 3
54
+
55
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
56
+ s.add_development_dependency(%q<rspec>, ["~> 1.3.0"])
57
+ s.add_runtime_dependency(%q<faraday>, ["~> 0.4.6"])
58
+ s.add_runtime_dependency(%q<faraday_middleware>, ["~> 0.1.0"])
59
+ s.add_runtime_dependency(%q<multi_xml>, ["~> 0.0.1"])
60
+ else
61
+ s.add_dependency(%q<rspec>, ["~> 1.3.0"])
62
+ s.add_dependency(%q<faraday>, ["~> 0.4.6"])
63
+ s.add_dependency(%q<faraday_middleware>, ["~> 0.1.0"])
64
+ s.add_dependency(%q<multi_xml>, ["~> 0.0.1"])
65
+ end
66
+ else
67
+ s.add_dependency(%q<rspec>, ["~> 1.3.0"])
68
+ s.add_dependency(%q<faraday>, ["~> 0.4.6"])
69
+ s.add_dependency(%q<faraday_middleware>, ["~> 0.1.0"])
70
+ s.add_dependency(%q<multi_xml>, ["~> 0.0.1"])
71
+ end
72
+ end
73
+
@@ -0,0 +1,36 @@
1
+ $:.unshift(File.expand_path(File.dirname(__FILE__)))
2
+
3
+ # TODO: use bundler
4
+ # Gems
5
+ require "faraday"
6
+ require "faraday_middleware"
7
+ require "multi_xml"
8
+
9
+ # Files
10
+ require "freckly/project"
11
+ require "freckly/entry"
12
+ require "freckly/faraday/parse_xml"
13
+
14
+ module Freckly
15
+ class << self
16
+ attr_accessor :token, :subdomain
17
+
18
+ def authed_get(path, options={})
19
+ results = authed_connection.get do |request|
20
+ request.url(path, options)
21
+ end.body
22
+ end
23
+
24
+ def authed_connection
25
+ headers = {
26
+ :user_agent => "Freckly",
27
+ "X-FreckleToken" => token
28
+ }
29
+ @connection ||= Faraday::Connection.new(:url => "http://#{subdomain}.letsfreckle.com", :headers => headers) do |builder|
30
+ builder.adapter Faraday.default_adapter
31
+ builder.use Faraday::Response::ParseXml
32
+ builder.use Faraday::Response::Mashify
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,21 @@
1
+ module Freckly
2
+ class Entry
3
+ class << self
4
+ def find_all_for_project(project_ids, options={})
5
+ Freckly.authed_get("/api/entries.xml", options.merge(:projects => project_ids))[:entries].map {|entry| new(entry) }
6
+ end
7
+ end
8
+
9
+ def initialize(entry_hashie)
10
+ @entry_hashie = entry_hashie
11
+ end
12
+
13
+ %w{ billable date description id minutes }.each do |method_name|
14
+ class_eval do
15
+ define_method method_name do
16
+ @entry_hashie.send(method_name)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ # Taken from:
2
+
3
+ module Faraday
4
+ class Response::ParseXml < Response::Middleware
5
+ MultiXml.engine = :rexml
6
+
7
+ def self.register_on_complete(env)
8
+ env[:response].on_complete do |response|
9
+ response[:body] = begin
10
+ MultiXml.parse(response[:body])
11
+ end
12
+ end
13
+ end
14
+
15
+ def initialize(app)
16
+ super
17
+ @parser = nil
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,25 @@
1
+ module Freckly
2
+ class Project
3
+ class << self
4
+ def all
5
+ Freckly.authed_get("/api/projects.xml").projects.map {|project| new(project) }
6
+ end
7
+ end
8
+
9
+ def initialize(project_hashie)
10
+ @project_hashie = project_hashie
11
+ end
12
+
13
+ def entries(options={})
14
+ Entry.find_all_for_project(id, options)
15
+ end
16
+
17
+ %w{ name id }.each do |method_name|
18
+ class_eval do
19
+ define_method method_name do
20
+ @project_hashie.send(method_name)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,27 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <entries type="array">
3
+ <entry>
4
+ <billable type="boolean">true</billable>
5
+ <created-at type="datetime">2009-10-16T09:57:22Z</created-at>
6
+ <date type="date">2009-10-11</date>
7
+ <description>freckle restful api test, bulk import</description>
8
+ <id type="integer">83601</id>
9
+ <minutes type="integer">120</minutes>
10
+ <project-id type="integer">8475</project-id>
11
+ <updated-at type="datetime">2009-10-16T09:57:22Z</updated-at>
12
+ <url nil="true"></url>
13
+ <user-id type="integer">5538</user-id>
14
+ </entry>
15
+ <entry>
16
+ <billable type="boolean">true</billable>
17
+ <created-at type="datetime">2009-10-16T09:57:22Z</created-at>
18
+ <date type="date">2009-10-12</date>
19
+ <description>freckle restful api test, bulk import</description>
20
+ <id type="integer">83602</id>
21
+ <minutes type="integer">30</minutes>
22
+ <project-id type="integer" nil="true"></project-id>
23
+ <updated-at type="datetime">2009-10-16T09:57:22Z</updated-at>
24
+ <url nil="true"></url>
25
+ <user-id type="integer">5538</user-id>
26
+ </entry>
27
+ </entries>
@@ -0,0 +1,25 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projects type="array">
3
+ <project>
4
+ <account-id type="integer">100</account-id>
5
+ <budget type="integer" nil="true"></budget>
6
+ <created-at type="datetime">2008-12-19T16:21:34Z</created-at>
7
+ <enabled type="boolean">true</enabled>
8
+ <id type="integer">1343</id>
9
+ <name>TestProject1</name>
10
+ <stepping type="integer">15</stepping>
11
+ <updated-at type="datetime">2008-12-19T16:21:34Z</updated-at>
12
+ <user-id type="integer" nil="true"></user-id>
13
+ </project>
14
+ <project>
15
+ <account-id type="integer">100</account-id>
16
+ <budget type="integer" nil="true"></budget>
17
+ <created-at type="datetime">2008-12-19T16:23:06Z</created-at>
18
+ <enabled type="boolean">true</enabled>
19
+ <id type="integer">1344</id>
20
+ <name>TestProject2</name>
21
+ <stepping type="integer">15</stepping>
22
+ <updated-at type="datetime">2008-12-19T16:23:06Z</updated-at>
23
+ <user-id type="integer" nil="true"></user-id>
24
+ </project>
25
+ </projects>
@@ -0,0 +1,40 @@
1
+ require "spec_helper"
2
+
3
+ describe Freckly::Entry do
4
+ before do
5
+ Freckly.token = "aaa"
6
+ Freckly.subdomain = "test"
7
+ stub_request(:any, /entries.xml/).to_return(:body => fixture("entries.xml"))
8
+ end
9
+
10
+ describe "Class methods" do
11
+ describe "#find" do
12
+ describe "the request" do
13
+ before { Freckly::Entry.find_all_for_project(123) }
14
+ subject { WebMock }
15
+
16
+ it { should have_requested(:get, "http://test.letsfreckle.com/api/entries.xml").with(:headers => {"X-FreckleToken" => "aaa"}, :query => {:projects => "123"}) }
17
+ end
18
+
19
+ describe "the response" do
20
+ before { @response = Freckly::Entry.find_all_for_project(123) }
21
+ subject { @response }
22
+
23
+ it { should be_a(Array) }
24
+
25
+ specify { subject.first.should be_a(Freckly::Entry) }
26
+ end
27
+ end
28
+ end
29
+
30
+ describe "Initialization" do
31
+ before(:all) { @entry = Freckly::Entry.find_all_for_project(123).first }
32
+ subject { @entry }
33
+
34
+ specify { subject.billable.should be_true }
35
+ specify { subject.date.should_not be_nil }
36
+ specify { subject.description.should == "freckle restful api test, bulk import" }
37
+ specify { subject.id.should == 83601 }
38
+ specify { subject.minutes.should == 120 }
39
+ end
40
+ end
@@ -0,0 +1,46 @@
1
+ require "spec_helper"
2
+
3
+ describe Freckly::Project do
4
+ before do
5
+ Freckly.token = "aaa"
6
+ Freckly.subdomain = "test"
7
+ stub_request(:any, /projects.xml$/).to_return(:body => fixture("projects.xml"))
8
+ end
9
+
10
+ describe "Class methods" do
11
+ describe "#all" do
12
+ describe "the request" do
13
+ before { Freckly::Project.all }
14
+ subject { WebMock }
15
+
16
+ it { should have_requested(:get, "http://test.letsfreckle.com/api/projects.xml").with(:headers => {"X-FreckleToken" => "aaa"}) }
17
+ end
18
+
19
+ describe "the response" do
20
+ before { @response = Freckly::Project.all }
21
+ subject { @response }
22
+
23
+ it { should be_a(Array) }
24
+
25
+ specify { subject.first.should be_a(Freckly::Project) }
26
+ end
27
+ end
28
+ end
29
+
30
+ describe "Initialization" do
31
+ before(:all) { @project = Freckly::Project.all.first }
32
+ subject { @project }
33
+
34
+ specify { subject.name.should == "TestProject1" }
35
+ specify { subject.id.should == 1343 }
36
+ end
37
+
38
+ describe "#entries" do
39
+ before { Freckly::Entry.stub!(:find_all_for_project).and_return([mock]) }
40
+ before(:all) { @project = Freckly::Project.all.first }
41
+
42
+ subject { @project.entries }
43
+
44
+ it { should be_a(Array) }
45
+ end
46
+ end
@@ -0,0 +1,4 @@
1
+ require "spec_helper"
2
+
3
+ describe "Freckly" do
4
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,17 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'freckly'
5
+
6
+ gem "rspec", "1.3.0"
7
+ require 'spec'
8
+ require 'spec/autorun'
9
+ require 'webmock/rspec'
10
+
11
+ def fixture(file_name)
12
+ File.read(File.expand_path(File.dirname(__FILE__) + "/fixtures/#{file_name}"))
13
+ end
14
+
15
+ Spec::Runner.configure do |config|
16
+ config.include WebMock
17
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: freckly
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 0
9
+ version: 0.0.0
10
+ platform: ruby
11
+ authors:
12
+ - reddavis
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-10-04 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 3
30
+ - 0
31
+ version: 1.3.0
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: faraday
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ - 4
44
+ - 6
45
+ version: 0.4.6
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: faraday_middleware
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ - 1
58
+ - 0
59
+ version: 0.1.0
60
+ type: :runtime
61
+ version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: multi_xml
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 0
71
+ - 0
72
+ - 1
73
+ version: 0.0.1
74
+ type: :runtime
75
+ version_requirements: *id004
76
+ description: Freckle Gem
77
+ email: reddavis@gmail.com
78
+ executables: []
79
+
80
+ extensions: []
81
+
82
+ extra_rdoc_files:
83
+ - LICENSE
84
+ - README.rdoc
85
+ files:
86
+ - .document
87
+ - .gitignore
88
+ - LICENSE
89
+ - README.rdoc
90
+ - Rakefile
91
+ - VERSION
92
+ - freckly.gemspec
93
+ - lib/freckly.rb
94
+ - lib/freckly/entry.rb
95
+ - lib/freckly/faraday/parse_xml.rb
96
+ - lib/freckly/project.rb
97
+ - spec/fixtures/entries.xml
98
+ - spec/fixtures/projects.xml
99
+ - spec/freckly/entry_spec.rb
100
+ - spec/freckly/project_spec.rb
101
+ - spec/freckly_spec.rb
102
+ - spec/spec.opts
103
+ - spec/spec_helper.rb
104
+ has_rdoc: true
105
+ homepage: http://github.com/reddavis/freckly
106
+ licenses: []
107
+
108
+ post_install_message:
109
+ rdoc_options:
110
+ - --charset=UTF-8
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ segments:
118
+ - 0
119
+ version: "0"
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ segments:
125
+ - 0
126
+ version: "0"
127
+ requirements: []
128
+
129
+ rubyforge_project:
130
+ rubygems_version: 1.3.6
131
+ signing_key:
132
+ specification_version: 3
133
+ summary: Freckle Gem
134
+ test_files:
135
+ - spec/freckly/entry_spec.rb
136
+ - spec/freckly/project_spec.rb
137
+ - spec/freckly_spec.rb
138
+ - spec/spec_helper.rb