opendaum 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+ gemspec
3
+
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (C) 2012 Daehyun Kim <https://github.com/hatemogi>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,16 @@
1
+ # Daum OpenAPI 라이브러리
2
+
3
+ 루비에서 [Daum](http://www.daum.net/) 오픈API를 쉽게 사용하기 위해 만든 프로젝트입니다.
4
+
5
+ # 설치 및 사용
6
+
7
+ > gem install opendaum
8
+
9
+ # 라이센스
10
+
11
+ MIT 라이센스를 사용합니다. 자세한 내용은 [LICENSE 파일내용](https://raw.github.com/hatemogi/opendaum/master/LICENSE)을 참고하세요.
12
+
13
+ # 참고자료
14
+
15
+ * <http://dna.daum.net/apis/>에 상세한 내용이 있습니다.
16
+
@@ -0,0 +1,18 @@
1
+ require 'bundler/setup'
2
+ require 'rdoc/task'
3
+ require 'rake/testtask'
4
+ require 'rake/clean'
5
+ require "bundler/gem_tasks"
6
+
7
+ Rake::RDocTask.new(:rdoc) do |t|
8
+ t.main = 'README.md'
9
+ t.rdoc_files.include('README.md', 'lib/**/*.rb')
10
+ t.options << '--all'
11
+ end
12
+
13
+ Rake::TestTask.new(:spec) do |t|
14
+ t.libs << 'spec'
15
+ t.test_files = FileList['spec/*_spec.rb']
16
+ end
17
+
18
+ task :default => :spec
@@ -0,0 +1,8 @@
1
+ require 'opendaum/version'
2
+ require 'opendaum/base'
3
+
4
+ module OpenDaum
5
+ autoload :Base, 'opendaum/base'
6
+ autoload :OAuth, 'opendaum/oauth'
7
+ autoload :Calendar, 'opendaum/calendar'
8
+ end
@@ -0,0 +1,16 @@
1
+ unless Hash.public_methods.include? :to_param
2
+ require 'cgi'
3
+ class Hash
4
+ def to_param
5
+ self.collect {|k, v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}"}.join('&')
6
+ end
7
+ end
8
+ end
9
+
10
+ module OpenDaum
11
+ module Base
12
+
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,77 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'json'
3
+
4
+ module OpenDaum::Calendar
5
+ class Base
6
+ def initialize access_token
7
+ @access_token = access_token
8
+ end
9
+
10
+ # {:name, :color, :description}
11
+ def create_category attrs = {}
12
+ @access_token.post '/calendar/category/create.json', {}
13
+ end
14
+
15
+ def categories
16
+ res = @access_token.get '/calendar/category/index.json'
17
+ JSON.parse(res.body).collect do |json|
18
+ Category.new @access_token, json
19
+ end
20
+ end
21
+
22
+ def events start_at = nil, end_at = nil, category_id = nil
23
+ params = {
24
+ :start_at => '2012-03-01',
25
+ :end_at => '2012-07-01'
26
+ }
27
+ params.merge!(:category_id => category_id) if category_id
28
+ url = "/calendar/event/index.json?" + params.to_param
29
+ r = @access_token.get url
30
+ JSON.parse(r.body).collect do |json|
31
+ Event.new @access_token, json
32
+ end
33
+ end
34
+
35
+ end
36
+
37
+ class Category
38
+ attr_accessor :id, :name, :color, :description, :display_order
39
+
40
+ def initialize access_token, attrs = {}
41
+ @access_token = access_token
42
+ attrs.each {|k, v| self.send("#{k}=", v) }
43
+ end
44
+
45
+ def create_event
46
+ end
47
+
48
+ def update attrs = {}
49
+ end
50
+
51
+ def events start_at = nil, end_at = nil
52
+ puts "호출은 됐음"
53
+ end
54
+
55
+ def << event
56
+ end
57
+
58
+ def inspect
59
+ "<\#캘린더:#{self.id}:#{self.name}:#{self.color}>"
60
+ end
61
+ end
62
+
63
+ class Event
64
+ attr_accessor :id, :title, :category_id, :start_at, :end_at, :allday, :url, :description, :attach, :location, :uid, :repeat, :rrule, :exdates, :completed_at
65
+
66
+ def initialize access_token, attrs = {}
67
+ @access_token = access_token
68
+ attrs.each {|k, v| self.send("#{k}=", v) }
69
+ end
70
+
71
+ def inspect
72
+ "<\#일정:#{self.id}:#{self.title}:#{self.start_at}-#{self.end_at}>"
73
+ end
74
+
75
+ end
76
+
77
+ end
@@ -0,0 +1,38 @@
1
+ require 'oauth'
2
+
3
+ module OpenDaum
4
+ module Factory
5
+ def calendar
6
+ Calendar::Base.new self
7
+ end
8
+ end
9
+
10
+ class OAuth
11
+ API_URL = 'https://apis.daum.net'
12
+
13
+ @@default_options = {
14
+ :site => API_URL,
15
+ :request_token_path => '/oauth/requestToken',
16
+ :access_token_path => '/oauth/accessToken'
17
+ }
18
+
19
+ def initialize consumer_key, consumer_secret, options = {}
20
+ @consumer = ::OAuth::Consumer.new consumer_key, consumer_secret, @@default_options.merge(options)
21
+ end
22
+
23
+ def request_token callback_url
24
+ @consumer.get_request_token :oauth_callback => callback_url
25
+ end
26
+
27
+ def get_access_token request_token, verifier
28
+ token = @consumer.get_access_token request_token, :oauth_verifier => verifier
29
+ token.extend Factory
30
+ end
31
+
32
+ def access_token token, token_secret
33
+ token = ::OAuth::AccessToken.new @consumer, token, token_secret
34
+ token.extend Factory
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module OpenDaum
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "opendaum/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'opendaum'
7
+ s.version = OpenDaum::VERSION
8
+ s.date = '2012-04-28'
9
+ s.summary = "OpenAPI for Daum"
10
+ s.description = "Daum OpenAPI Library. API for Cafe, Calendar, and Tistory."
11
+ s.author = 'Daehyun Kim'
12
+ s.email = 'https://github.com/hatemogi'
13
+ s.homepage = 'https://github.com/hatemogi/opendaum.git'
14
+ s.files = `git ls-files`.split("\n") - %w[.gitignore]
15
+ s.license = 'MIT'
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_runtime_dependency 'oauth', '>= 0.4.5'
21
+ s.add_runtime_dependency 'json'
22
+ s.add_development_dependency 'minitest'
23
+ s.add_development_dependency 'sinatra'
24
+ s.add_development_dependency 'sinatra-contrib'
25
+ s.add_development_dependency 'haml'
26
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opendaum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,8 +12,19 @@ cert_chain: []
12
12
  date: 2012-04-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: rest-client
16
- requirement: &70229105269620 !ruby/object:Gem::Requirement
15
+ name: oauth
16
+ requirement: &70101690058160 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.4.5
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70101690058160
25
+ - !ruby/object:Gem::Dependency
26
+ name: json
27
+ requirement: &70101690057220 !ruby/object:Gem::Requirement
17
28
  none: false
18
29
  requirements:
19
30
  - - ! '>='
@@ -21,10 +32,43 @@ dependencies:
21
32
  version: '0'
22
33
  type: :runtime
23
34
  prerelease: false
24
- version_requirements: *70229105269620
35
+ version_requirements: *70101690057220
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: minitest
27
- requirement: &70229105269180 !ruby/object:Gem::Requirement
38
+ requirement: &70101690056480 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70101690056480
47
+ - !ruby/object:Gem::Dependency
48
+ name: sinatra
49
+ requirement: &70101690056040 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70101690056040
58
+ - !ruby/object:Gem::Dependency
59
+ name: sinatra-contrib
60
+ requirement: &70101690055620 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70101690055620
69
+ - !ruby/object:Gem::Dependency
70
+ name: haml
71
+ requirement: &70101690055160 !ruby/object:Gem::Requirement
28
72
  none: false
29
73
  requirements:
30
74
  - - ! '>='
@@ -32,17 +76,23 @@ dependencies:
32
76
  version: '0'
33
77
  type: :development
34
78
  prerelease: false
35
- version_requirements: *70229105269180
79
+ version_requirements: *70101690055160
36
80
  description: Daum OpenAPI Library. API for Cafe, Calendar, and Tistory.
37
81
  email: https://github.com/hatemogi
38
82
  executables: []
39
83
  extensions: []
40
84
  extra_rdoc_files: []
41
85
  files:
42
- - spec/base_spec.rb
43
- - spec/calendar_spec.rb
44
- - spec/oauth_spec.rb
45
- - spec/opendaum_spec.rb
86
+ - Gemfile
87
+ - LICENSE
88
+ - README.md
89
+ - Rakefile
90
+ - lib/opendaum.rb
91
+ - lib/opendaum/base.rb
92
+ - lib/opendaum/calendar.rb
93
+ - lib/opendaum/oauth.rb
94
+ - lib/opendaum/version.rb
95
+ - opendaum.gemspec
46
96
  homepage: https://github.com/hatemogi/opendaum.git
47
97
  licenses:
48
98
  - MIT
@@ -58,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
58
108
  version: '0'
59
109
  segments:
60
110
  - 0
61
- hash: -2817201858404185691
111
+ hash: -2562195047640184793
62
112
  required_rubygems_version: !ruby/object:Gem::Requirement
63
113
  none: false
64
114
  requirements:
@@ -67,15 +117,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
117
  version: '0'
68
118
  segments:
69
119
  - 0
70
- hash: -2817201858404185691
120
+ hash: -2562195047640184793
71
121
  requirements: []
72
122
  rubyforge_project:
73
123
  rubygems_version: 1.8.11
74
124
  signing_key:
75
125
  specification_version: 3
76
126
  summary: OpenAPI for Daum
77
- test_files:
78
- - spec/base_spec.rb
79
- - spec/calendar_spec.rb
80
- - spec/oauth_spec.rb
81
- - spec/opendaum_spec.rb
127
+ test_files: []
@@ -1,12 +0,0 @@
1
- require File.expand_path('../helper', __FILE__)
2
-
3
- describe OpenDaum::Base do
4
- include OpenDaum::Base
5
- it "should test something" do
6
- url('/calendar/category/index.json').must_equal "#{OpenDaum::Base::API_URL}/calendar/category/index.json"
7
- end
8
-
9
- it "extends Hash to_param" do
10
- {:a => 3, :b => 'abc'}.to_param.must_equal 'a=3&b=abc'
11
- end
12
- end
@@ -1,9 +0,0 @@
1
- require File.expand_path('../helper', __FILE__)
2
-
3
- describe Calendar do
4
-
5
- it "should list calendar" do
6
- # assert Calendar.new.list
7
-
8
- end
9
- end
@@ -1,13 +0,0 @@
1
- require File.expand_path('../helper', __FILE__)
2
-
3
- describe OpenDaum::OAuth do
4
- before do
5
- @oauth = OAuth.new 'c2e87e04-b5a2-4eb1-8e8f-7640d0cacbe8', 'UtJSvNQXAsnxtbyTngklOD24EE9cj.DIKud_K48vfLh5qj5.64aHuQ00'
6
- end
7
-
8
- it "should test something" do
9
- p @oauth.request_token
10
- end
11
-
12
-
13
- end
@@ -1,8 +0,0 @@
1
- require File.expand_path('../helper', __FILE__)
2
-
3
- describe OpenDaum do
4
- it "should load something" do
5
- assert true
6
- end
7
- end
8
-