hatenaapigraph 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
File without changes
data/README ADDED
@@ -0,0 +1,22 @@
1
+ = Hatena::API::Graph -- Hatena Graph API
2
+
3
+ == SYNOPSIS
4
+
5
+ require 'rubygems'
6
+ require 'hatena/api/graph'
7
+
8
+ graph = Hatena::API::Graph.new('username', 'password')
9
+ graph.post('graphname', Time.now, 10.5)
10
+ graph.post(graphname, timestamp, value)
11
+
12
+ == Installation
13
+
14
+ # gem install hatenaapigraph
15
+
16
+ == License
17
+
18
+ Hatena::API::Graph is released under the MIT license.
19
+
20
+ == Author
21
+
22
+ secondlife@no.spam@hatena.ne.jp
data/Rakefile ADDED
@@ -0,0 +1,103 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/clean'
4
+ require 'rake/testtask'
5
+ require 'rake/packagetask'
6
+ require 'rake/gempackagetask'
7
+ require 'rake/rdoctask'
8
+ require 'rake/contrib/rubyforgepublisher'
9
+ require 'fileutils'
10
+ include FileUtils
11
+ require File.join(File.dirname(__FILE__), 'lib', 'hatena', 'api', 'graph')
12
+
13
+ AUTHOR = "gorou"
14
+ EMAIL = "your contact email for bug fixes and info"
15
+ DESCRIPTION = "description of gem"
16
+ RUBYFORGE_PROJECT = "hatenaapigraph"
17
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
18
+ BIN_FILES = %w( )
19
+
20
+
21
+ NAME = "hatenaapigraph"
22
+ REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
23
+ VERS = ENV['VERSION'] || (Hatena::API::Graph::VERSION::STRING + (REV ? ".#{REV}" : ""))
24
+ CLEAN.include ['**/.*.sw?', '*.gem', '.config']
25
+ RDOC_OPTS = ['--quiet', '--title', "hatenaapigraph documentation",
26
+ "--opname", "index.html",
27
+ "--line-numbers",
28
+ "--main", "README",
29
+ "--inline-source"]
30
+
31
+ desc "Packages up hatenaapigraph gem."
32
+ task :default => [:test]
33
+ task :package => [:clean]
34
+
35
+ Rake::TestTask.new("test") { |t|
36
+ t.libs << "test"
37
+ t.pattern = "test/**/*_test.rb"
38
+ t.verbose = true
39
+ }
40
+
41
+ spec =
42
+ Gem::Specification.new do |s|
43
+ s.name = NAME
44
+ s.version = VERS
45
+ s.platform = Gem::Platform::RUBY
46
+ s.has_rdoc = true
47
+ s.extra_rdoc_files = ["README", "CHANGELOG"]
48
+ s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)/']
49
+ s.summary = DESCRIPTION
50
+ s.description = DESCRIPTION
51
+ s.author = AUTHOR
52
+ s.email = EMAIL
53
+ s.homepage = HOMEPATH
54
+ s.executables = BIN_FILES
55
+ s.rubyforge_project = RUBYFORGE_PROJECT
56
+ s.bindir = "bin"
57
+ s.require_path = "lib"
58
+ s.autorequire = "hatenaapigraph"
59
+
60
+ #s.add_dependency('activesupport', '>=1.3.1')
61
+ #s.required_ruby_version = '>= 1.8.2'
62
+
63
+ s.files = %w(README CHANGELOG Rakefile) +
64
+ Dir.glob("{bin,doc,test,lib,templates,generator,extras,website,script}/**/*") +
65
+ Dir.glob("ext/**/*.{h,c,rb}") +
66
+ Dir.glob("examples/**/*.rb") +
67
+ Dir.glob("tools/*.rb")
68
+
69
+ # s.extensions = FileList["ext/**/extconf.rb"].to_a
70
+ end
71
+
72
+ Rake::GemPackageTask.new(spec) do |p|
73
+ p.need_tar = true
74
+ p.gem_spec = spec
75
+ end
76
+
77
+ task :install do
78
+ name = "#{NAME}-#{VERS}.gem"
79
+ sh %{rake package}
80
+ sh %{sudo gem install pkg/#{name}}
81
+ end
82
+
83
+ task :uninstall => [:clean] do
84
+ sh %{sudo gem uninstall #{NAME}}
85
+ end
86
+
87
+ Rake::RDocTask.new { |rdoc|
88
+ rdoc.rdoc_dir = 'html'
89
+ rdoc.options += RDOC_OPTS
90
+ rdoc.template = "#{ENV['template']}.rb" if ENV['template']
91
+ if ENV['DOC_FILES']
92
+ rdoc.rdoc_files.include(ENV['DOC_FILES'].split(/,\s*/))
93
+ else
94
+ rdoc.rdoc_files.include('README', 'CHANGELOG')
95
+ rdoc.rdoc_files.include('lib/**/*.rb')
96
+ end
97
+ }
98
+
99
+ desc "Publish to RubyForge"
100
+ task :rubyforge => [:rdoc, :package] do
101
+ Rake::RubyForgePublisher.new(RUBYFORGE_PROJECT, 'secondlife').upload
102
+ end
103
+
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'base64'
4
+ require 'sha1'
5
+ require 'net/http'
6
+ require 'uri'
7
+ require 'time'
8
+
9
+ module Hatena
10
+ module API
11
+ class GraphError < StandardError; end
12
+ class Graph
13
+ module VERSION #:nodoc:
14
+ MAJOR = 0
15
+ MINOR = 0
16
+ TINY = 2
17
+
18
+ STRING = [MAJOR, MINOR, TINY].join('.')
19
+ end
20
+
21
+ DATE_FORMAT = '%Y-%m-%d'
22
+ GRAPH_API_URI = URI.parse 'http://graph.hatena.ne.jp/api/post'
23
+
24
+ def initialize(username, password)
25
+ @username = username
26
+ @password = password
27
+ end
28
+
29
+ def post(graphname, date, value)
30
+ value = value.to_f
31
+ date = date.strftime DATE_FORMAT
32
+ headers = {
33
+ 'Access' => 'application/x.atom+xml, application/xml, text/xml, */*',
34
+ 'X-WSSE' => wsse(@username, @password),
35
+ }
36
+ params = {
37
+ :graphname => URI::encode(graphname),
38
+ :date => date,
39
+ :value => value,
40
+ }
41
+ res = http_post GRAPH_API_URI, params, headers
42
+ raise GraphError.new("request not successed: #{res}") if res.code != '201'
43
+ res
44
+ end
45
+
46
+ private
47
+ def http_post(url, params, headers)
48
+ req = ::Net::HTTP::Post.new(url.path, headers)
49
+ req.form_data = params
50
+ req.basic_auth url.user, url.password if url.user
51
+ ::Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }
52
+ end
53
+
54
+ def wsse(username, password)
55
+ nonce = (1..10).collect {|x| sprintf("%02X", rand(256)) }.join
56
+ timestamp = Time.now.iso8601
57
+ digest = bchomp Digest::SHA1::digest(nonce + timestamp + password)
58
+ %Q[UsernameToken Username="#{username}", PasswordDigest="#{digest}", Nonce="#{bchomp nonce}", Created="#{timestamp}"]
59
+ end
60
+
61
+ def bchomp(str)
62
+ ::Base64::encode64(str).chomp
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class HatenaapigraphTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def test_truth
9
+ assert true
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/hatena/api/graph'
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.11
3
+ specification_version: 1
4
+ name: hatenaapigraph
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.0.2
7
+ date: 2006-11-06 00:00:00 +09:00
8
+ summary: description of gem
9
+ require_paths:
10
+ - lib
11
+ email: your contact email for bug fixes and info
12
+ homepage: http://hatenaapigraph.rubyforge.org
13
+ rubyforge_project: hatenaapigraph
14
+ description: description of gem
15
+ autorequire: hatenaapigraph
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ authors:
29
+ - gorou
30
+ files:
31
+ - README
32
+ - CHANGELOG
33
+ - Rakefile
34
+ - test/hatenaapigraph_test.rb
35
+ - test/test_helper.rb
36
+ - lib/hatenaapigraph
37
+ - lib/hatena
38
+ - lib/hatena/api
39
+ - lib/hatena/api/graph.rb
40
+ test_files: []
41
+
42
+ rdoc_options:
43
+ - --quiet
44
+ - --title
45
+ - hatenaapigraph documentation
46
+ - --opname
47
+ - index.html
48
+ - --line-numbers
49
+ - --main
50
+ - README
51
+ - --inline-source
52
+ - --exclude
53
+ - ^(examples|extras)/
54
+ extra_rdoc_files:
55
+ - README
56
+ - CHANGELOG
57
+ executables: []
58
+
59
+ extensions: []
60
+
61
+ requirements: []
62
+
63
+ dependencies: []
64
+