ragoon 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 07d318395124190dab619ce4e4a26ff7b99b4a9a
4
+ data.tar.gz: 754dce5cb93edecd58970e83f3e757e84c601e61
5
+ SHA512:
6
+ metadata.gz: 387eef07a6a6864c5c7100c2386335b2c0045c4764dc515b130207d113493b5124f94c1c5d82e4364b3fed1140c8ce22e538c7c06d12f80e361e6012f2543f3c
7
+ data.tar.gz: de91e8c3790114977d03bae42aaa00c4da3143e9438b4298e13ce8ee6627414ed03bfb1bcfb2eea1c2015ad5de0eec39230d7afece218490f629c35f650490de
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor/bundle/
11
+ /.secret_options
12
+ /build/
13
+ /release/
14
+
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 SHIOYA, Hiromu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,22 @@
1
+ # Ragoon
2
+
3
+ Ragoon is simple Garoon 3 API Client.
4
+
5
+ - https://cybozudev.zendesk.com/hc/ja/categories/200157760-Garoon-API
6
+
7
+ ## Usage
8
+
9
+ ```
10
+ service = Ragoon::Services::Schedule.new
11
+ events = service.schedule_get_event
12
+
13
+ => [
14
+ {:title=>"予定あり", :period=>"13:00〜14:00", :facility=>""},
15
+ {:title=>"セクションMTG", :period=>"15:00〜15:30", :facility=>["会議室"]},
16
+ {:title=>"予定あり", :period=>"終日", :facility=>""}
17
+ ]
18
+
19
+ ```
20
+ ## License
21
+
22
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'ragoon'
5
+
6
+ require 'pry'
7
+ Pry.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install --path=vendor/bundle
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,39 @@
1
+ require 'ragoon/version'
2
+ require 'ragoon/services'
3
+ require 'ragoon/xml'
4
+ require 'ragoon/client'
5
+
6
+ Dir.glob('./lib/ragoon/services/*.rb', &method(:require))
7
+
8
+ require 'nokogiri'
9
+ require 'rest-client'
10
+
11
+ module Ragoon
12
+ @@secret_options = {}
13
+
14
+ def self.garoon_endpoint
15
+ ENV['GAROON_ENDPOINT'] || secret_options[:garoon_endpoint] || raise_option_error('endpoint')
16
+ end
17
+
18
+ def self.garoon_username
19
+ ENV['GAROON_USERNAME'] || secret_options[:garoon_username] || raise_option_error('username')
20
+ end
21
+
22
+ def self.garoon_password
23
+ ENV['GAROON_PASSWORD'] || secret_options[:garoon_password] || raise_option_error('password')
24
+ end
25
+
26
+ def self.raise_option_error(type)
27
+ raise "must specify garoon_#{type} by ENV or `./.secret_options`."
28
+ end
29
+
30
+ private
31
+
32
+ def self.secret_options
33
+ if @@secret_options.empty?
34
+ raise '`./.secret_options` is required.' unless File.exists?('./.secret_options')
35
+ @@secret_options = eval(File.read('./.secret_options'))
36
+ end
37
+ @@secret_options
38
+ end
39
+ end
@@ -0,0 +1,17 @@
1
+ class Ragoon::Client
2
+ attr_reader :endpoint, :response
3
+
4
+ def initialize(endpoint)
5
+ @endpoint = endpoint
6
+ end
7
+
8
+ def request(action_name, body_node)
9
+ @action_name = action_name
10
+ @body_node = body_node
11
+ @response = RestClient.post(endpoint, Ragoon::XML.render(action_name, body_node))
12
+ end
13
+
14
+ def result_set
15
+ @result_set ||= Nokogiri::XML.parse(response.body)
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ class Ragoon::Services
2
+ SERVICE_LOCATIONS = {
3
+ schedule: '/cbpapi/schedule/api?',
4
+ }.freeze
5
+
6
+ attr_reader :client, :action_type
7
+
8
+ def initialize
9
+ @action_type = self.class.name.split('::').pop.downcase.to_sym
10
+ @client = Ragoon::Client.new(self.endpoint)
11
+ end
12
+
13
+ def endpoint
14
+ endpoint = URI(Ragoon.garoon_endpoint)
15
+ "#{endpoint.scheme}://#{endpoint.host}#{endpoint.path}#{SERVICE_LOCATIONS[action_type]}"
16
+ end
17
+ end
@@ -0,0 +1,59 @@
1
+ class Ragoon::Services::Schedule < Ragoon::Services
2
+ def schedule_get_events(options = {})
3
+ action_name = 'ScheduleGetEvents'
4
+
5
+ options = default_options(action_name).merge(options)
6
+
7
+ body_node = Ragoon::XML.create_node(action_name)
8
+ parameter_node = Ragoon::XML.create_node(
9
+ 'parameters',
10
+ start: options[:start].strftime('%FT%T'),
11
+ end: options[:end].strftime('%FT%T')
12
+ )
13
+ body_node.add_child(parameter_node)
14
+
15
+ client.request(action_name, body_node)
16
+
17
+ events = client.result_set.xpath('//schedule_event').find_all { |ev| ev[:event_type] == 'normal' }.map do |event|
18
+ public_event = event[:public_type] == 'public'
19
+ {
20
+ title: public_event ? event[:detail] : '予定あり',
21
+ period: start_and_end(event),
22
+ facility: public_event ? facility_names(event) : '',
23
+ }
24
+ end
25
+ end
26
+
27
+ def facility_names(event)
28
+ event.xpath('ev:members', ev: "http://schemas.cybozu.co.jp/schedule/2008").
29
+ children.map { |c| c.xpath('ev:facility', ev: "http://schemas.cybozu.co.jp/schedule/2008").first }.
30
+ compact.map { |n| n[:name] }
31
+ end
32
+
33
+ def start_and_end(event)
34
+ if event[:allday] == 'true'
35
+ '終日'
36
+ else
37
+ period = event.children.xpath('ev:datetime', ev: "http://schemas.cybozu.co.jp/schedule/2008").first
38
+
39
+ return 'error' if period.nil?
40
+
41
+ start_time = Time.parse(period[:start]).localtime.strftime('%R')
42
+ end_time = event[:start_only] == 'true' ? '' : Time.parse(period[:end]).localtime.strftime('%R')
43
+ "#{start_time}〜#{end_time}"
44
+ end
45
+ end
46
+
47
+ def default_options(action_name)
48
+ case action_name
49
+ when 'ScheduleGetEvents'
50
+ today = Date.today
51
+ {
52
+ start: Time.local(today.year, today.month, today.day, 0).utc,
53
+ end: Time.local(today.year, today.month, today.day + 1, 0).utc,
54
+ }
55
+ else
56
+ {}
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,3 @@
1
+ module Ragoon
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,53 @@
1
+ module Ragoon::XML
2
+ ACTION_PLACEHOLDER = '<!-- REQUEST_ACTION -->'.freeze
3
+ BODY_PLACEHOLDER = '<!-- REQUEST_BODY -->'.freeze
4
+
5
+ def self.render(action_name, body_node)
6
+ template.dup.
7
+ gsub!(ACTION_PLACEHOLDER, action_name).
8
+ gsub!(BODY_PLACEHOLDER, body_node.to_xml)
9
+ end
10
+
11
+ def self.create_node(name, attributes = {})
12
+ node = Nokogiri::XML::Node.new(name, Nokogiri::XML.parse('<xml />'))
13
+ attributes.each do |key, value|
14
+ node[key.to_s] = value
15
+ end
16
+ node
17
+ end
18
+
19
+ def self.template
20
+ <<"XML"
21
+ <?xml version="1.0" encoding="UTF-8"?>
22
+ <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope"
23
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
24
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
25
+ xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
26
+ xmlns:base_services="http://wsdl.cybozu.co.jp/base/2008">
27
+ <SOAP-ENV:Header>
28
+ <Action SOAP-ENV:mustUnderstand="1"
29
+ xmlns="http://schemas.xmlsoap.org/ws/2003/03/addressing">
30
+ #{ACTION_PLACEHOLDER}
31
+ </Action>
32
+ <Security xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility"
33
+ SOAP-ENV:mustUnderstand="1"
34
+ xmlns="http://schemas.xmlsoap.org/ws/2002/12/secext">
35
+ <UsernameToken wsu:Id="id">
36
+ <Username>#{Ragoon.garoon_username}</Username>
37
+ <Password>#{Ragoon.garoon_password}</Password>
38
+ </UsernameToken>
39
+ </Security>
40
+ <Timestamp SOAP-ENV:mustUnderstand="1" Id="id"
41
+ xmlns="http://schemas.xmlsoap.org/ws/2002/07/utility">
42
+ <Created>#{Time.now.iso8601}</Created>
43
+ <Expires>#{(Time.now + 60 * 60 * 24).iso8601}</Expires>
44
+ </Timestamp>
45
+ <Locale>jp</Locale>
46
+ </SOAP-ENV:Header>
47
+ <SOAP-ENV:Body>
48
+ #{BODY_PLACEHOLDER}
49
+ </SOAP-ENV:Body>
50
+ </SOAP-ENV:Envelope>
51
+ XML
52
+ end
53
+ end
@@ -0,0 +1,26 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'ragoon/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'ragoon'
7
+ spec.version = Ragoon::VERSION
8
+ spec.authors = ['SHIOYA, Hiromu']
9
+ spec.email = ['kwappa.856@gmail.com']
10
+
11
+ spec.summary = 'Ragoon is a simple Garoon 3 API client.'
12
+ spec.description = spec.summary
13
+ spec.homepage = 'https://github.com/kwappa/ragoon'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'rest-client', '~> 1.8.0'
22
+ spec.add_dependency 'nokogiri', '~> 1.6.6'
23
+ spec.add_development_dependency 'bundler', '~> 1.10'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'pry'
26
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ragoon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - SHIOYA, Hiromu
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.8.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.8.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.6.6
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.6.6
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Ragoon is a simple Garoon 3 API client.
84
+ email:
85
+ - kwappa.856@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - CODE_OF_CONDUCT.md
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/ragoon.rb
100
+ - lib/ragoon/client.rb
101
+ - lib/ragoon/services.rb
102
+ - lib/ragoon/services/schedule.rb
103
+ - lib/ragoon/version.rb
104
+ - lib/ragoon/xml.rb
105
+ - ragoon.gemspec
106
+ homepage: https://github.com/kwappa/ragoon
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.4.5.1
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Ragoon is a simple Garoon 3 API client.
130
+ test_files: []