atabodi 0.0.1

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: 2ab492e4636ff6462f41fa4fce6a53dded2dd471
4
+ data.tar.gz: 0cd4f002dc545bf0721cca446df31dc6abeeb7ba
5
+ SHA512:
6
+ metadata.gz: 391370f5ce42b58a678846d5147b54e5519e6ddb8591a446575595bc7e876740c493997d8519bfb309c9d17f18d96ec0a437de341362a11b13c00d64f40c8419
7
+ data.tar.gz: d3ea501e28e7932d70f02a0fd70f04ca32ea32cd5a521a1dda582a42e79d860594dfedd50eaca7f90eaa49cfa393df58442f8158742ae2f4fe83f5f9a72df724
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in atabodi.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Seiei Higa
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,29 @@
1
+ # Atabodi
2
+
3
+ Unofficial idobata.io api client
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'atabodi'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install atabodi
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/atabodi/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/atabodi.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 'atabodi/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "atabodi"
8
+ spec.version = Atabodi::VERSION
9
+ spec.authors = ["Seiei Higa"]
10
+ spec.email = ["hanachin@gmail.com"]
11
+ spec.summary = %q{idobata.io bot api client}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_runtime_dependency "jsonism"
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ end
data/idobata.yml ADDED
@@ -0,0 +1,113 @@
1
+ ---
2
+ "$schema": http://json-schema.org/draft-04/hyper-schema
3
+ properties:
4
+ bot:
5
+ "$ref": "#/definitions/bot"
6
+ bots:
7
+ "$ref": "#/definitions/bots"
8
+ type:
9
+ - object
10
+ description: A schema for a unofficial idobata API.
11
+ links:
12
+ - href: https://idobata.io
13
+ rel: self
14
+ title: Idobata API
15
+ definitions:
16
+ bots:
17
+ "$schema": http://json-schema.org/draft-04/hyper-schema
18
+ description: idobata robot guys.
19
+ title: Bots
20
+ type:
21
+ - object
22
+ properties:
23
+ bots:
24
+ type:
25
+ - array
26
+ items:
27
+ "$ref": "#/definitions/bot"
28
+ links:
29
+ - description: List existing bots.
30
+ href: "/api/bots/"
31
+ method: GET
32
+ rel: self
33
+ title: list
34
+ bot:
35
+ "$schema": http://json-schema.org/draft-04/hyper-schema
36
+ description: A idobata robot guy.
37
+ title: Bot
38
+ type:
39
+ - object
40
+ properties:
41
+ id:
42
+ "$ref": "#/definitions/bot/definitions/id"
43
+ name:
44
+ "$ref": "#/definitions/bot/definitions/name"
45
+ icon_url:
46
+ "$ref": "#/definitions/bot/definitions/icon_url"
47
+ api_token:
48
+ "$ref": "#/definitions/bot/definitions/api_token"
49
+ status:
50
+ "$ref": "#/definitions/bot/definitions/status"
51
+ channel_name:
52
+ "$ref": "#/definitions/bot/definitions/channel_name"
53
+ links:
54
+ # update icon is multipart request...
55
+ # - title: update_icon
56
+ # description: Update a icon of bot.
57
+ # href: "/api/bots/{(%23%2Fdefinitions%2Fbot%2Fdefinitions%2Fid)}"
58
+ # method: PUT
59
+ # rel: update
60
+ # schema:
61
+ # properties:
62
+ # icon:
63
+ # "$ref": "#/definitions/bot/definitions/icon"
64
+ # type:
65
+ # - object
66
+ definitions:
67
+ id:
68
+ description: unique identifier of bot
69
+ example: 3543
70
+ readOnly: true
71
+ type:
72
+ - integer
73
+ name:
74
+ description: unique name of bot
75
+ example: hi
76
+ pattern: "^[a-zA-Z0-9_-]{1,15}$"
77
+ readOnly: false
78
+ type:
79
+ - string
80
+ icon_url:
81
+ description: a icon of bot
82
+ example: https://idobata.s3.amazonaws.com/uploads/bot/icon/3543/mihashi.jpg
83
+ format: uri
84
+ readOnly: true
85
+ type:
86
+ - string
87
+ api_token:
88
+ description: "unique api token of bot, uuid.gsub('-', '')"
89
+ example: 0123456789abcdef0123456789abcdef
90
+ pattern: "^[0-9a-f]{32}"
91
+ readOnly: true
92
+ type:
93
+ - string
94
+ status:
95
+ description: status of bot
96
+ example: offline
97
+ pattern: "(offline|online)"
98
+ readOnly: true
99
+ type:
100
+ - string
101
+ channel_name:
102
+ description: a protected channel name of pusher
103
+ example: presence-guy_3543
104
+ readOnly: true
105
+ type:
106
+ - string
107
+ # icon:
108
+ # description: an icon data of bot
109
+ # type:
110
+ # - string
111
+ # media:
112
+ # binaryEncoding: base64
113
+ # type: image/jpeg
@@ -0,0 +1,60 @@
1
+ require 'yaml'
2
+ require 'json'
3
+ require 'forwardable'
4
+ require 'jsonism'
5
+
6
+ module Atabodi
7
+ DEFAULT_SCHEMA = YAML.load_file File.expand_path('../../idobata.yml', __dir__)
8
+
9
+ class Client
10
+ extend Forwardable
11
+
12
+ def_delegator :client, :respond_to?, :respond_to_missing?
13
+
14
+ def initialize(schema: DEFAULT_SCHEMA, api_token:)
15
+ @schema = schema
16
+ @api_token = api_token
17
+ client.connection.headers = client.connection.headers.merge(headers)
18
+ end
19
+
20
+ def method_missing(name, *args)
21
+ if client.respond_to?(name)
22
+ client.send(name, *args)
23
+ else
24
+ raise NoMethodError, name
25
+ end
26
+ end
27
+
28
+ def update_bot_icon(id:, file_path:)
29
+ c = Faraday.new(url: client.base_url) do |connection|
30
+ connection.request :multipart
31
+ connection.request :url_encoded
32
+ connection.response :json
33
+ connection.adapter :net_http
34
+ end
35
+
36
+ # FIXME MIME TYPE
37
+ params = {'bot[icon]' => Faraday::UploadIO.new(file_path, 'image/jpeg')}
38
+ res = c.put("/api/bots/#{id}", params, headers)
39
+
40
+ Jsonism::Response.new(
41
+ client: client,
42
+ resource_class: Jsonism::Resources.const_get('Bot'),
43
+ response: res
44
+ )
45
+ end
46
+
47
+ private
48
+
49
+ def client
50
+ @client ||= Jsonism::Client.new(schema: @schema)
51
+ end
52
+
53
+ def headers
54
+ {
55
+ 'User-Agent' => "Atabodi v#{Atabodi::VERSION}",
56
+ 'X-API-Token' => @api_token
57
+ }
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,3 @@
1
+ module Atabodi
2
+ VERSION = "0.0.1"
3
+ end
data/lib/atabodi.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "atabodi/version"
2
+ require "atabodi/client"
3
+
4
+ module Atabodi
5
+ # Your code goes here...
6
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: atabodi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Seiei Higa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jsonism
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - hanachin@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - atabodi.gemspec
68
+ - idobata.yml
69
+ - lib/atabodi.rb
70
+ - lib/atabodi/client.rb
71
+ - lib/atabodi/version.rb
72
+ homepage: ''
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.2.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: idobata.io bot api client
96
+ test_files: []
97
+ has_rdoc: