mypeople 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b32377c4f564000f821785a5c76644f4f1c666d8
4
+ data.tar.gz: ebe1a3597f0af06953cb19a03b4883ac3ff1f89e
5
+ SHA512:
6
+ metadata.gz: ee0c62ce7d9b419e1d8c0a8d75bd323a9933009b55b5d1488c553737d0540dbec743b649c81576db5ecc4542f44fadcdcb4aac04f386990d1510a07db84021b4
7
+ data.tar.gz: fdedeb80ae9f435e60e7debd06c2e478069bf20d2483d3e1d5427be5fc7ad241fce283beaa4686e7f02867a4bd2cb9a5dfa11ffe30cf0dac6f3ba843340e4d10
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mypeople.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Taekmin Kim
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # Mypeople
2
+
3
+ Daum에서 제공하는 API를 루비 버전으로 묶은 gem입니다.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'mypeople'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install mypeople
18
+
19
+ ## Usage
20
+
21
+ ### Setup
22
+
23
+ Mypeople.configure do |config|
24
+ config.host = "https://api.daum.net"
25
+ config.key = "다음 API 콘솔에서 발급 받은 키"
26
+ end
27
+
28
+ ### 그룹의 멤버 구하기
29
+
30
+ group_id = "GID_XXX"
31
+ Mypeople::Group.members(group_id)
32
+
33
+ ### 그룹에 메세지(텍스트) 보내기
34
+ group_id = "GID_XXX"
35
+ Mypeople::Group.send(group_id, "Hello World")
36
+
37
+ ### 그룹에서 나가기
38
+ group_id = "GID_XXX"
39
+ Mypeople::Group.exit(group_id)
40
+
41
+ ### 친구의 프로필 얻기
42
+ buddy_id = "BU_XXX"
43
+ Mypeople::Member.find(buddy_id)
44
+
45
+ ### 친구(1:1)에게 메세지(텍스트) 보내기
46
+ buddy_id = "BU_XXX"
47
+ Mypeople::Member.send(buddy_id, "Hello World")
48
+
49
+ ### 다른 예제
50
+ test.rb 참고
51
+
52
+ ## Rails Example
53
+
54
+ [https://github.com/tantara/mypeople-rails](https://github.com/tantara/mypeople-rails)
55
+
56
+
57
+ ## Contributing
58
+
59
+ 1. Fork it ( http://github.com/<my-github-username>/mypeople/fork )
60
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
61
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
62
+ 4. Push to the branch (`git push origin my-new-feature`)
63
+ 5. Create new Pull Request
64
+
65
+
66
+ ## Contact
67
+
68
+ 1. Taekmin Kim (tantara.tm@gmail.com)
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,9 @@
1
+ module Mypeople
2
+ class Bot < Requirement
3
+ class << self
4
+ def exit(group_id)
5
+ client.exit_from_group(buddy_id)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,160 @@
1
+ require 'net/http'
2
+ require 'forwardable'
3
+ require 'openssl'
4
+
5
+ module Mypeople
6
+ class Configuration
7
+ CONFIGURABLE_ATTRIBUTES = [
8
+ :host,
9
+ :key
10
+ ]
11
+
12
+ attr_accessor *CONFIGURABLE_ATTRIBUTES
13
+
14
+ def self.configurable_attributes
15
+ CONFIGURABLE_ATTRIBUTES
16
+ end
17
+
18
+ def initialize(attrs = {})
19
+ self.attributes = attrs
20
+ end
21
+
22
+ def attributes=(attrs = {})
23
+ attrs.each { |key, value| instance_variable_set("@#{key}", value) }
24
+ end
25
+
26
+ def http
27
+ uri = URI.parse(self.host)
28
+ @http ||= Net::HTTP.new(uri.host, uri.port)
29
+ @http.use_ssl = true
30
+ @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
31
+ @http
32
+ end
33
+
34
+ def data
35
+ @data = {"apikey" => @key}
36
+ end
37
+ end
38
+
39
+ class Client
40
+ extend Forwardable
41
+
42
+ APIS = {
43
+ :send_message_to_buddy => {:method => "POST", :path => "/mypeople/buddy/send.json"}, # 1:1 대화 메세지 보내기
44
+ :buddy_profile => {:method => "GET", :path => "/mypeople/profile/buddy.json"}, # 친구 프로필 정보 보기
45
+ :get_members => {:method => "GET", :path => "/mypeople/group/members.json"}, # 그룹 대화방 친구 목록 보기
46
+ :send_message_to_group => {:method => "POST", :path => "/mypeople/group/send.json"}, # 그룹 대화방에 메세지 보내기
47
+ :exit_from_group => {:method => "GET", :path => "/mypeople/group/exit.json"}, # 그룹 대화방 나가기
48
+ :download_file => {:method => "GET", :path => "/mypeople/file/download.json"} # 파일 및 사진 받기
49
+ }
50
+
51
+ def_delegators :configuration, :credentials, *Configuration.configurable_attributes
52
+
53
+ def initialize(attrs = {})
54
+ self.configuration.attributes = attrs
55
+ end
56
+
57
+ def configure
58
+ yield configuration if block_given?
59
+ end
60
+
61
+ def configuration
62
+ @configuration ||= Configuration.new
63
+ end
64
+
65
+ def request(method, path, data)
66
+ http = configuration.http
67
+ data = configuration.data.merge(data)
68
+
69
+ case method
70
+ when "GET"
71
+ get(http, path, data)
72
+ when "POST"
73
+ post(http, path, data)
74
+ end
75
+ end
76
+
77
+ def get(http, path, data)
78
+ data = URI.encode_www_form(data)
79
+ resp, body = http.send_request("GET", "#{path}?#{data}")
80
+
81
+ resp.body
82
+ end
83
+
84
+ def post(http, path, data)
85
+ data = URI.encode_www_form(data)
86
+ resp, body = http.send_request("POST", path, data)
87
+
88
+ resp.body
89
+ end
90
+
91
+ def send_message_to_buddy(buddy_id, content, attach = nil)
92
+ method = APIS[:send_message_to_buddy][:method]
93
+ path = APIS[:send_message_to_buddy][:path]
94
+ data = if content.empty?
95
+ {
96
+ "buddyId" => buddy_id,
97
+ "attach" => attach
98
+ }
99
+ else
100
+ {
101
+ "buddyId" => buddy_id,
102
+ "content" => content
103
+ }
104
+ end
105
+
106
+ request(method, path, data)
107
+ end
108
+
109
+ def buddy_profile(buddy_id)
110
+ method = APIS[:buddy_profile][:method]
111
+ path = APIS[:buddy_profile][:path]
112
+ data = {
113
+ "buddyId" => buddy_id
114
+ }
115
+
116
+ request(method, path, data)
117
+ end
118
+
119
+ def get_members(group_id)
120
+ method = APIS[:get_members][:method]
121
+ path = APIS[:get_members][:path]
122
+ data = {
123
+ "groupId" => group_id
124
+ }
125
+
126
+ request(method, path, data)
127
+ end
128
+
129
+ def send_message_to_group(group_id, content, attach = nil)
130
+ method = APIS[:send_message_to_group][:method]
131
+ path = APIS[:send_message_to_group][:path]
132
+ data = {
133
+ "groupId" => group_id,
134
+ "content" => content
135
+ }
136
+
137
+ request(method, path, data)
138
+ end
139
+
140
+ def exit_from_group(group_id)
141
+ method = APIS[:exit_from_group][:method]
142
+ path = APIS[:exit_from_group][:path]
143
+ data = {
144
+ "groupId" => group_id
145
+ }
146
+
147
+ request(method, path, data)
148
+ end
149
+
150
+ def download_file(file_id, file_name)
151
+ method = APIS[:download_file][:method]
152
+ path = APIS[:download_file][:path]
153
+ data = {
154
+ "fileId" => file_id
155
+ }
156
+
157
+ request(method, path, data)
158
+ end
159
+ end
160
+ end
@@ -0,0 +1,7 @@
1
+ module Mypeople
2
+ class File < Requirement
3
+ def self.download(file_id, file_name)
4
+ client.download_file(file_id, file_name)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,21 @@
1
+ module Mypeople
2
+ class Group < Requirement
3
+ class << self
4
+ def members(group_id)
5
+ client.get_members(group_id)
6
+ end
7
+
8
+ def send(group_id, content)
9
+ if content.is_a?(String) # string msg
10
+ client.send_message_to_group(group_id, content)
11
+ else # file msg
12
+ client.send_message_to_group(group_id, "", content)
13
+ end
14
+ end
15
+
16
+ def exit(group_id)
17
+ client.exit_from_group(group_id)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ module Mypeople
2
+ class Member < Requirement
3
+ class << self
4
+ def find(buddy_id)
5
+ client.buddy_profile(buddy_id)
6
+ end
7
+
8
+ def send(buddy_id, content)
9
+ if content.is_a?(String) # string msg
10
+ client.send_message_to_buddy(buddy_id, content)
11
+ else # file msg
12
+ client.send_message_to_buddy(buddy_id, "", content)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ module Mypeople
2
+ class Requirement
3
+ class << self
4
+ def client
5
+ Mypeople.client
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Mypeople
2
+ VERSION = "0.0.3"
3
+ end
data/lib/mypeople.rb ADDED
@@ -0,0 +1,40 @@
1
+ require "logger"
2
+
3
+ module Mypeople
4
+ autoload :Bot, 'mypeople/bot'
5
+ autoload :Client, 'mypeople/client'
6
+ autoload :File, 'mypeople/file'
7
+ autoload :Group, 'mypeople/group'
8
+ autoload :Member, 'mypeople/member'
9
+ autoload :Requirement, 'mypeople/requirement'
10
+
11
+ # Raise this when we hit a Trello error.
12
+ Error = Class.new(StandardError)
13
+
14
+ # This specific error is thrown when your key is invalid. You should get a new one.
15
+ InvalidKey = Class.new(Error)
16
+
17
+ # This error is thrown when your client has not been configured
18
+ ConfigurationError = Class.new(Error)
19
+
20
+ def self.logger
21
+ @logger ||= Logger.new(STDOUT)
22
+ end
23
+
24
+ def self.logger=(logger)
25
+ @logger = logger
26
+ end
27
+
28
+ def self.client
29
+ @client ||= Client.new
30
+ end
31
+
32
+ def self.configure(&block)
33
+ reset!
34
+ client.configure(&block)
35
+ end
36
+
37
+ def self.reset!
38
+ @client = nil
39
+ end
40
+ end
data/mypeople.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mypeople/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mypeople"
8
+ spec.version = Mypeople::VERSION
9
+ spec.authors = ["Taekmin Kim"]
10
+ spec.email = ["tantara.tm@gmail.com"]
11
+ spec.summary = "Ruby gem for mypeople api"
12
+ spec.description = ""
13
+ spec.homepage = "https://github.com/tantara/mypeople-ruby"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ end
data/test.rb ADDED
@@ -0,0 +1,32 @@
1
+ $LOAD_PATH.unshift 'lib'
2
+ require 'mypeople'
3
+
4
+ include Mypeople
5
+
6
+ Mypeople.configure do |config|
7
+ config.host = "https://apis.daum.net"
8
+ config.key = "API_KEY"
9
+ end
10
+
11
+ TEST_GROUP_ID = "GID_XXXX"
12
+ TEST_USER_ID = "BU_XXXXX"
13
+ TEST_CONTENT = "Mypeople ruby gem test #{Time.now}"
14
+ TEST_FILE_ID = "myp_pub:XXXXX"
15
+
16
+ # 그룹의 멤버들 얻기
17
+ #puts Mypeople::Group.members(TEST_GROUP_ID)
18
+
19
+ # 그룹에 메세지 보내기
20
+ #Mypeople::Group.send(TEST_GROUP_ID, TEST_CONTENT)
21
+
22
+ # 친구의 프로필 얻기
23
+ #puts Mypeople::Member.find(TEST_USER_ID)
24
+
25
+ # 파일
26
+ #puts Mypeople::File.download(TEST_FILE_ID, "profile.jpg")
27
+
28
+ # 친구(1:1)에게 메세지 보내기
29
+ #Mypeople::Member.send(TEST_USER_ID, TEST_CONTENT)
30
+
31
+ # 그룹에서 나가기
32
+ #Mypeople::Group.exit(TEST_GROUP_ID)
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mypeople
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Taekmin Kim
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: ''
42
+ email:
43
+ - tantara.tm@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/mypeople.rb
54
+ - lib/mypeople/bot.rb
55
+ - lib/mypeople/client.rb
56
+ - lib/mypeople/file.rb
57
+ - lib/mypeople/group.rb
58
+ - lib/mypeople/member.rb
59
+ - lib/mypeople/requirement.rb
60
+ - lib/mypeople/version.rb
61
+ - mypeople.gemspec
62
+ - test.rb
63
+ homepage: https://github.com/tantara/mypeople-ruby
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.0.3
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Ruby gem for mypeople api
87
+ test_files: []