lostinpatterns-dailymile-client 0.1.0
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/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +46 -0
- data/Rakefile +59 -0
- data/VERSION +1 -0
- data/dailymile-client.gemspec +50 -0
- data/lib/dailymile-client/authenticated_user.rb +43 -0
- data/lib/dailymile-client/client.rb +93 -0
- data/lib/dailymile-client.rb +29 -0
- data/test/dailymile-client_test.rb +7 -0
- data/test/test_helper.rb +10 -0
- metadata +67 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 lostinpatterns
|
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,46 @@
|
|
1
|
+
= dailymile-client
|
2
|
+
|
3
|
+
Example usage:
|
4
|
+
|
5
|
+
dailymile = DailymileClient.new(CONSUMER_KEY, CONSUMER_SECRET, :token => '', :secret => '')
|
6
|
+
|
7
|
+
# get a specific entry
|
8
|
+
dailymile.entry(1)
|
9
|
+
|
10
|
+
# get the public feed
|
11
|
+
dailymile.entries :page => 2
|
12
|
+
|
13
|
+
# get the user's entries
|
14
|
+
dailymile.entries("ben")
|
15
|
+
|
16
|
+
# get friends of the given user
|
17
|
+
dailymile.friends("ben")
|
18
|
+
|
19
|
+
# get the info for a user
|
20
|
+
dailymile.user "ben"
|
21
|
+
|
22
|
+
# post a workout
|
23
|
+
dailymile.authenticated_user.post_workout("hill repeats. tough stuff!",
|
24
|
+
:duration => 30.minutes, :type => 'running',
|
25
|
+
:distance => { :value => 5.5, :units => 'miles' })
|
26
|
+
|
27
|
+
# post a note
|
28
|
+
dailymile.authenticated_user.post_workout "think today is a rest day!"
|
29
|
+
|
30
|
+
# you and friends feed for the authenticated user
|
31
|
+
dailymile.authenticated_user.entries
|
32
|
+
|
33
|
+
== Note on Patches/Pull Requests
|
34
|
+
|
35
|
+
* Fork the project.
|
36
|
+
* Make your feature addition or bug fix.
|
37
|
+
* Add tests for it. This is important so I don't break it in a
|
38
|
+
future version unintentionally.
|
39
|
+
* Commit, do not mess with rakefile, version, or history.
|
40
|
+
(if you want to have your own version, that is fine but
|
41
|
+
bump version in a commit by itself I can ignore when I pull)
|
42
|
+
* Send me a pull request. Bonus points for topic branches.
|
43
|
+
|
44
|
+
== Copyright
|
45
|
+
|
46
|
+
Copyright (c) 2009 lostinpatterns. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "dailymile-client"
|
8
|
+
gem.summary = %Q{TODO: one-line summary of your gem}
|
9
|
+
gem.description = %Q{TODO: longer description of your gem}
|
10
|
+
gem.email = "blweiner@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/lostinpatterns/dailymile-client"
|
12
|
+
gem.authors = ["lostinpatterns"]
|
13
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
14
|
+
end
|
15
|
+
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'rake/testtask'
|
21
|
+
Rake::TestTask.new(:test) do |test|
|
22
|
+
test.libs << 'lib' << 'test'
|
23
|
+
test.pattern = 'test/**/*_test.rb'
|
24
|
+
test.verbose = true
|
25
|
+
end
|
26
|
+
|
27
|
+
begin
|
28
|
+
require 'rcov/rcovtask'
|
29
|
+
Rcov::RcovTask.new do |test|
|
30
|
+
test.libs << 'test'
|
31
|
+
test.pattern = 'test/**/*_test.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
rescue LoadError
|
35
|
+
task :rcov do
|
36
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
if File.exist?('VERSION.yml')
|
48
|
+
config = YAML.load(File.read('VERSION.yml'))
|
49
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
50
|
+
else
|
51
|
+
version = ""
|
52
|
+
end
|
53
|
+
|
54
|
+
rdoc.rdoc_dir = 'rdoc'
|
55
|
+
rdoc.title = "dailymile-client #{version}"
|
56
|
+
rdoc.rdoc_files.include('README*')
|
57
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
58
|
+
end
|
59
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{dailymile-client}
|
5
|
+
s.version = "0.1.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["lostinpatterns"]
|
9
|
+
s.date = %q{2009-08-01}
|
10
|
+
s.description = %q{TODO: longer description of your gem}
|
11
|
+
s.email = %q{blweiner@gmail.com}
|
12
|
+
s.extra_rdoc_files = [
|
13
|
+
"LICENSE",
|
14
|
+
"README.rdoc"
|
15
|
+
]
|
16
|
+
s.files = [
|
17
|
+
".document",
|
18
|
+
".gitignore",
|
19
|
+
"LICENSE",
|
20
|
+
"README.rdoc",
|
21
|
+
"Rakefile",
|
22
|
+
"VERSION",
|
23
|
+
"dailymile-client.gemspec",
|
24
|
+
"lib/dailymile-client.rb",
|
25
|
+
"lib/dailymile-client/authenticated_user.rb",
|
26
|
+
"lib/dailymile-client/client.rb",
|
27
|
+
"test/dailymile-client_test.rb",
|
28
|
+
"test/test_helper.rb"
|
29
|
+
]
|
30
|
+
s.has_rdoc = true
|
31
|
+
s.homepage = %q{http://github.com/lostinpatterns/dailymile-client}
|
32
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
33
|
+
s.require_paths = ["lib"]
|
34
|
+
s.rubygems_version = %q{1.3.1}
|
35
|
+
s.summary = %q{TODO: one-line summary of your gem}
|
36
|
+
s.test_files = [
|
37
|
+
"test/dailymile-client_test.rb",
|
38
|
+
"test/test_helper.rb"
|
39
|
+
]
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
|
+
s.specification_version = 2
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
46
|
+
else
|
47
|
+
end
|
48
|
+
else
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Dailymile
|
2
|
+
|
3
|
+
class AuthenticatedUser
|
4
|
+
|
5
|
+
attr_reader :client
|
6
|
+
|
7
|
+
def initialize(client)
|
8
|
+
@client = client
|
9
|
+
end
|
10
|
+
|
11
|
+
def post_note(message)
|
12
|
+
create_entry :message => message
|
13
|
+
end
|
14
|
+
|
15
|
+
def post_workout(message, workout_params = {})
|
16
|
+
create_entry :message => message, :workout => workout_params
|
17
|
+
end
|
18
|
+
|
19
|
+
def delete_entry(entry_id)
|
20
|
+
client.delete "/entries/#{entry_id}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def comment(entry_id, comment)
|
24
|
+
client.post "/entries/#{entry_id}/comments", :body => comment
|
25
|
+
end
|
26
|
+
|
27
|
+
def like(entry_id)
|
28
|
+
client.post "/entries/#{entry_id}/likes"
|
29
|
+
end
|
30
|
+
|
31
|
+
def entries
|
32
|
+
client.get "/entries/friends"
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def create_entry(params = {})
|
38
|
+
client.post "/entries", params
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module Dailymile
|
2
|
+
|
3
|
+
class Client
|
4
|
+
|
5
|
+
DEFAULT_FORMAT = 'json'
|
6
|
+
DEFAULT_REQUEST_HEADERS = {
|
7
|
+
'Accept' => "application/#{DEFAULT_FORMAT}",
|
8
|
+
'Content-Type' => "application/#{DEFAULT_FORMAT}"
|
9
|
+
}
|
10
|
+
|
11
|
+
attr_reader :authenticated_user
|
12
|
+
|
13
|
+
def initialize(consumer_key, consumer_secret, options = {})
|
14
|
+
@consumer = OAuth::Consumer.new(consumer_key, consumer_secret,
|
15
|
+
:site => File.join(API_PROTOCOL, API_HOST))
|
16
|
+
@access_token = OAuth::AccessToken.new(@consumer, options[:token], options[:secret])
|
17
|
+
@authenticated_user = AuthenticatedUser.new(self)
|
18
|
+
end
|
19
|
+
|
20
|
+
def entries(*args)
|
21
|
+
options = extract_options_from_args!(args)
|
22
|
+
username = args.first if args.first.is_a?(String)
|
23
|
+
entries_path = username.nil? ? '/entries' : "/entries/#{username}"
|
24
|
+
|
25
|
+
get entries_path, options
|
26
|
+
end
|
27
|
+
|
28
|
+
def friends(username)
|
29
|
+
get "/people/#{username}/friends"
|
30
|
+
end
|
31
|
+
|
32
|
+
def entry(id)
|
33
|
+
get "/entries/#{id}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def user(username)
|
37
|
+
get "/people/#{username}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def post(path, params = {})
|
41
|
+
set_format! path
|
42
|
+
handle_response @access_token.post(path, params.to_json, DEFAULT_REQUEST_HEADERS)
|
43
|
+
end
|
44
|
+
|
45
|
+
def get(path, params = {})
|
46
|
+
set_format! path
|
47
|
+
path << params.to_query_string unless params.empty?
|
48
|
+
handle_response @access_token.get(path)
|
49
|
+
end
|
50
|
+
|
51
|
+
def delete(path)
|
52
|
+
handle_response @access_token.delete(path)
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def extract_options_from_args!(args)
|
58
|
+
args.last.is_a?(Hash) ? args.pop : {}
|
59
|
+
end
|
60
|
+
|
61
|
+
def set_format!(path)
|
62
|
+
unless path =~ /.+\.\w+$/
|
63
|
+
path << ".#{DEFAULT_FORMAT}"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def handle_response(response)
|
68
|
+
case response
|
69
|
+
when Net::HTTPOK: JSON.parse(response.body)
|
70
|
+
when Net::HTTPNotFound: raise NotFound
|
71
|
+
when Net::HTTPUnauthorized: raise Unauthorized
|
72
|
+
when Net::HTTPBadGateway: raise Unavailable
|
73
|
+
when Net::HTTPCreated
|
74
|
+
return JSON.parse(response.body), response['Location']
|
75
|
+
when Net::HTTPServiceUnavailable
|
76
|
+
if response['Retry-After']
|
77
|
+
raise RateLimitExceeded
|
78
|
+
else
|
79
|
+
raise Unavailable
|
80
|
+
end
|
81
|
+
else
|
82
|
+
if response.code.to_s == '422'
|
83
|
+
errors = JSON.parse(response.body)
|
84
|
+
raise UnprocessableEntity, errors
|
85
|
+
else
|
86
|
+
raise DailymileException, 'Unkown response!'
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
gem 'oauth', '>= 0.3.5'
|
4
|
+
|
5
|
+
require File.dirname(__FILE__) + '/dailymile-client/client'
|
6
|
+
require File.dirname(__FILE__) + '/dailymile-client/authenticated_user'
|
7
|
+
|
8
|
+
module Dailymile
|
9
|
+
|
10
|
+
#API_HOST = 'api.dailymile.com'
|
11
|
+
API_HOST = 'localhost:3000'
|
12
|
+
API_PROTOCOL = 'http://'
|
13
|
+
|
14
|
+
class DailymileException < StandardError; end
|
15
|
+
|
16
|
+
class NotFound < DailymileException; end
|
17
|
+
class Unauthorized < DailymileException; end
|
18
|
+
class RateLimitExceeded < DailymileException; end
|
19
|
+
class Unavailable < DailymileException; end
|
20
|
+
class UnprocessableEntity < DailymileException
|
21
|
+
attr_reader :errors
|
22
|
+
|
23
|
+
def initialize(errors)
|
24
|
+
@errors = errors
|
25
|
+
super
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lostinpatterns-dailymile-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- lostinpatterns
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-01 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: "TODO: longer description of your gem"
|
17
|
+
email: blweiner@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- .document
|
27
|
+
- .gitignore
|
28
|
+
- LICENSE
|
29
|
+
- README.rdoc
|
30
|
+
- Rakefile
|
31
|
+
- VERSION
|
32
|
+
- dailymile-client.gemspec
|
33
|
+
- lib/dailymile-client.rb
|
34
|
+
- lib/dailymile-client/authenticated_user.rb
|
35
|
+
- lib/dailymile-client/client.rb
|
36
|
+
- test/dailymile-client_test.rb
|
37
|
+
- test/test_helper.rb
|
38
|
+
has_rdoc: true
|
39
|
+
homepage: http://github.com/lostinpatterns/dailymile-client
|
40
|
+
licenses:
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options:
|
43
|
+
- --charset=UTF-8
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
requirements: []
|
59
|
+
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 1.3.5
|
62
|
+
signing_key:
|
63
|
+
specification_version: 2
|
64
|
+
summary: "TODO: one-line summary of your gem"
|
65
|
+
test_files:
|
66
|
+
- test/dailymile-client_test.rb
|
67
|
+
- test/test_helper.rb
|