me2day-ruby 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) Sukjoon Kim
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.
21
+
data/Manifest ADDED
@@ -0,0 +1,8 @@
1
+ LICENSE
2
+ README.markdown
3
+ Rakefile
4
+ lib/me2day.rb
5
+ lib/me2day/client.rb
6
+ test/client_test.rb
7
+ test/test_helper.rb
8
+ Manifest
data/README.markdown ADDED
@@ -0,0 +1,61 @@
1
+ An API client for me2day(http://me2day.net), a Twitter-like Korean popular social networking service.
2
+
3
+ Install
4
+ =====
5
+
6
+ $ (sudo) gem install me2day-ruby
7
+
8
+
9
+ me2day "Easy Authentication (Web-based)"
10
+ =====
11
+
12
+ @auth_url = Me2day::Client.get_auth_url(:app_key => "YOUR_ME2DAY_APPLICATION_KEY")
13
+ => "http://me2day.net/api/start_auth?token=XXXXXXXXXXXXXX"
14
+
15
+ .. then redirection to the auth_url
16
+ .. and then user accept the auth
17
+ .. and then in callback
18
+
19
+ token, user_id, user_key, result = request.params["token"], request.params["user_id"], request.params["user_key"], request.params["result"]
20
+
21
+ if result == 'true'
22
+
23
+ @client = Me2day::Client.new(
24
+ :user_id => request.params[:user_id],
25
+ :user_key => request.params[:user_key],
26
+ :app_key => "YOUR_ME2DAY_APPLICATION_KEY"
27
+ )
28
+
29
+ @client.get("/noop")
30
+ => {"error"=>{"code"=>"0", "description"=>nil, "message"=>"\354\204\261\352\263\265\355\226\210\354\212\265\353\213\210\353\213\244."}}
31
+
32
+ @client.post("/create_post/[me2_user_id]", :query => { 'post[body]' => "Hello! me2!!" })
33
+
34
+ OR
35
+
36
+ @client.create_post('me2_user_id', 'post[body]' => "Hi!, How are you!!")
37
+
38
+ end
39
+
40
+
41
+ Todos
42
+ =====
43
+
44
+ * Add more methods
45
+ * Error Handling
46
+ * DRY cleaning!
47
+
48
+
49
+ Dependencies
50
+ =====
51
+
52
+ * httparty (https://github.com/jnunemaker/httparty)
53
+
54
+
55
+ References
56
+ =====
57
+
58
+ * http://codian.springnote.com/pages/1645274
59
+ * http://codian.springnote.com/pages/89009
60
+ * http://thinkr.egloos.com/2584593
61
+
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+ require 'shoulda/tasks'
5
+
6
+ task :default => ["test:units"]
7
+
8
+ desc "Run basic tests"
9
+ Rake::TestTask.new("test:units") { |t|
10
+ t.pattern = 'test/**/*_test.rb'
11
+ t.verbose = true
12
+ t.warning = true
13
+ }
14
+
15
+ Echoe.new('me2day-ruby', '0.1.0') do |p|
16
+ p.description = "a me2day API client"
17
+ p.url = "https://github.com/sjoonk/me2day-ruby"
18
+ p.author = "Sukjoon Kim"
19
+ p.email = "sjoonk@gmail.com"
20
+ p.ignore_pattern = ["tmp/*", "script/*"]
21
+ p.development_dependencies = ['httparty']
22
+ end
@@ -0,0 +1,50 @@
1
+ module Me2day
2
+ class Client
3
+ include HTTParty
4
+ base_uri "http://me2day.net/api"
5
+ DEFAULT_FORMAT = 'xml'
6
+
7
+ def initialize(options={})
8
+ @app_key = options[:app_key]
9
+ @user_id = options[:user_id]
10
+ @user_key = options[:user_key]
11
+ self.class.headers 'me2_application_key' => @app_key
12
+ self.class.default_params.merge!(:uid => @user_id, :ukey => u_key(@user_key))
13
+ end
14
+
15
+ def self.get_auth_url(options={})
16
+ raise "app_key is required" unless options[:app_key]
17
+ self.headers 'me2_application_key' => options[:app_key]
18
+ get("/get_auth_url.json")["url"]
19
+ end
20
+
21
+ # General helper methods
22
+
23
+ def get(path, options={}); self.class.get(path, options).parsed_response end
24
+ def post(path, options={}); self.class.post(path, options).parsed_response end
25
+
26
+ # API wrappers
27
+
28
+ def noop
29
+ get("/noop")
30
+ end
31
+
32
+ def create_post(user_id, options={})
33
+ format = options.delete(:format) || DEFAULT_FORMAT
34
+ post("/create_post/#{user_id}.#{format}", :query => options)
35
+ end
36
+
37
+ def create_comment(post_id, body)
38
+ format = options.delete(:format) || DEFAULT_FORMAT
39
+ post("/create_comment.#{format}", :query => {:post_id => post_id, :body => body})
40
+ end
41
+
42
+ private
43
+
44
+ def u_key(user_key)
45
+ nonce = rand(0xffffffff).to_s(16)
46
+ nonce + Digest::MD5.hexdigest(nonce + user_key)
47
+ end
48
+
49
+ end
50
+ end
data/lib/me2day.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'digest/md5'
2
+ require 'httparty'
3
+ require 'me2day/client'
4
+
5
+ module Me2day
6
+ VERSION = '0.1.0'
7
+ end
8
+
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{me2day-ruby}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Sukjoon Kim"]
9
+ s.date = %q{2011-01-12}
10
+ s.description = %q{a me2day API client}
11
+ s.email = %q{sjoonk@gmail.com}
12
+ s.extra_rdoc_files = ["LICENSE", "README.markdown", "lib/me2day.rb", "lib/me2day/client.rb"]
13
+ s.files = ["LICENSE", "README.markdown", "Rakefile", "lib/me2day.rb", "lib/me2day/client.rb", "test/client_test.rb", "test/test_helper.rb", "Manifest", "me2day-ruby.gemspec"]
14
+ s.homepage = %q{https://github.com/sjoonk/me2day-ruby}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Me2day-ruby", "--main", "README.markdown"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{me2day-ruby}
18
+ s.rubygems_version = %q{1.4.2}
19
+ s.summary = %q{a me2day API client}
20
+ s.test_files = ["test/client_test.rb", "test/test_helper.rb"]
21
+
22
+ if s.respond_to? :specification_version then
23
+ s.specification_version = 3
24
+
25
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
+ s.add_development_dependency(%q<httparty>, [">= 0"])
27
+ else
28
+ s.add_dependency(%q<httparty>, [">= 0"])
29
+ end
30
+ else
31
+ s.add_dependency(%q<httparty>, [">= 0"])
32
+ end
33
+ end
@@ -0,0 +1,18 @@
1
+ require File.join(File.dirname(__FILE__), "/test_helper")
2
+
3
+ class ClientTest < Test::Unit::TestCase
4
+ include Me2day
5
+
6
+ context "A client instance" do
7
+
8
+ setup do
9
+ @client = Client.new
10
+ end
11
+
12
+ should "be kind of Me2day client" do
13
+ assert_kind_of Me2day::Client, @client
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'shoulda'
3
+ require 'redgreen'
4
+ require 'mocha'
5
+
6
+ lib_files = File.join(File.dirname(__FILE__), "..", "lib")
7
+
8
+ Dir.glob(File.join(lib_files, "**")).each do |file|
9
+ require file
10
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: me2day-ruby
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Sukjoon Kim
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-12 00:00:00 +09:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: httparty
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ description: a me2day API client
36
+ email: sjoonk@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.markdown
44
+ - lib/me2day.rb
45
+ - lib/me2day/client.rb
46
+ files:
47
+ - LICENSE
48
+ - README.markdown
49
+ - Rakefile
50
+ - lib/me2day.rb
51
+ - lib/me2day/client.rb
52
+ - test/client_test.rb
53
+ - test/test_helper.rb
54
+ - Manifest
55
+ - me2day-ruby.gemspec
56
+ has_rdoc: true
57
+ homepage: https://github.com/sjoonk/me2day-ruby
58
+ licenses: []
59
+
60
+ post_install_message:
61
+ rdoc_options:
62
+ - --line-numbers
63
+ - --inline-source
64
+ - --title
65
+ - Me2day-ruby
66
+ - --main
67
+ - README.markdown
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 11
85
+ segments:
86
+ - 1
87
+ - 2
88
+ version: "1.2"
89
+ requirements: []
90
+
91
+ rubyforge_project: me2day-ruby
92
+ rubygems_version: 1.4.2
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: a me2day API client
96
+ test_files:
97
+ - test/client_test.rb
98
+ - test/test_helper.rb