diesel-api-dsl 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c09f2251953d171164fa4883b9aad83e9a1d7d9
4
- data.tar.gz: 7c885dc69abd71c3e3c897e20bfcbf5ca141c166
3
+ metadata.gz: 5205a50b3bdbd62a8a5dd19471fe81656a943b82
4
+ data.tar.gz: 45e98aae757b989153b9323ec7d670234a14ed83
5
5
  SHA512:
6
- metadata.gz: 8347d51bde9ca019c77d813ce453199603736228b00e69294bc4af670959101b978218d39bf18ef1f7b04afdfe2483d7b2fae19eb9bde26f51c528592d442496
7
- data.tar.gz: b67551247eab1cde0aa09fb14f34f60e1d6e4824d1d4016eae690d3f34d92662b1d2e738e032a81b33295151a59613e021ba43d5ae0d7135c857093f9d86f1ba
6
+ metadata.gz: ade33fbdca31713aba34eb525aa4ba89825875b0b9e6a0d073bf58b38762734f886cfe3f2818f80b7efb317440106c148af5cf930c8b9f70744fde7004697717
7
+ data.tar.gz: 1d89e1a7bafc5ab3f8ffd4ab3e754ad9a50adcf50e6ca6e757ac6a3c25069363445caa64442b803d711289aa4fc95df11d7a6f58001d28a932b7709798c28035
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # Diesel
2
2
 
3
- Create API Clients From an DSL
3
+ Create API Clients from Swagger specifications
4
4
 
5
5
  ## Installation
6
6
 
7
7
  Add this line to your application's Gemfile:
8
8
 
9
- gem 'diesel'
9
+ gem 'diesel-api-dsl'
10
10
 
11
11
  And then execute:
12
12
 
@@ -18,7 +18,16 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ ```ruby
22
+ PivotalTracker = Diesel.load_path("pivotal_tracker.json")
23
+ client = PivotalTracker.new(api_token: 'afaketoken')
24
+ client.create_story(
25
+ project_id: '1234567',
26
+ story: {
27
+ name: 'Testing Pivotal API',
28
+ story_type: :chore
29
+ })
30
+ ```
22
31
 
23
32
  ## Contributing
24
33
 
@@ -1,3 +1,4 @@
1
+ require 'diesel/version'
1
2
  require 'diesel/api_error'
2
3
  require 'diesel/utils/inflections'
3
4
  require 'diesel/api_base'
@@ -73,6 +74,8 @@ module Diesel
73
74
  endpoint.config_middleware do
74
75
  use Diesel::Middleware::Debug
75
76
 
77
+ use Diesel::Middleware::SetHeader, 'User-Agent' => "diesel-rb/#{Diesel::VERSION}"
78
+
76
79
  if spec.produces.any?
77
80
  use Diesel::Middleware::SetHeader, 'Content-Type' => spec.produces.first
78
81
  end
@@ -85,6 +88,10 @@ module Diesel
85
88
  id: Diesel::Utils::Inflections.underscore(name).to_sym,
86
89
  in: security_def.in,
87
90
  name: security_def.name
91
+ when 'oauth2'
92
+ require 'diesel/middleware/auth/oauth2'
93
+ use Diesel::Middleware::Auth::OAuth2,
94
+ id: Diesel::Utils::Inflections.underscore(name).to_sym
88
95
  else
89
96
  raise APIError, "Unsupported security definition: #{security_def.type}"
90
97
  end
@@ -0,0 +1,24 @@
1
+ module Diesel
2
+ module Middleware
3
+ module Auth
4
+ class OAuth2
5
+
6
+ AUTHORIZATION_HEADER = 'Authorization'
7
+ AUTHORIZATION_HEADER_FORMAT = 'Bearer %s'
8
+
9
+ def initialize(app, options)
10
+ @app = app
11
+ @id = options[:id]
12
+ end
13
+
14
+ def call(env)
15
+ context = env[:context]
16
+ auth_options = context.options[@id]
17
+ env[:request_headers][AUTHORIZATION_HEADER] = AUTHORIZATION_HEADER_FORMAT % auth_options[:token]
18
+ @app.call(env)
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
@@ -17,9 +17,9 @@ module Diesel
17
17
  attribute :max_items
18
18
  attribute :min_items
19
19
  attribute :unique_items, type: :boolean
20
+ attribute :items
20
21
 
21
22
  list :enum
22
- list :items
23
23
  end
24
24
  end
25
25
  end
@@ -4,9 +4,17 @@ require 'diesel/swagger/property'
4
4
  module Diesel
5
5
  module Swagger
6
6
  class Definition < Node
7
+ attr_reader :id
8
+
7
9
  attribute :required
8
10
  attribute :discriminator
11
+
9
12
  hash :properties
13
+
14
+ def initialize(id)
15
+ super()
16
+ @id = id
17
+ end
10
18
  end
11
19
  end
12
20
  end
@@ -130,6 +130,11 @@ module Diesel
130
130
  h
131
131
  end
132
132
 
133
+ def to_json
134
+ MultiJson.dump(serializable_hash)
135
+ end
136
+ alias :to_s :to_json
137
+
133
138
  private
134
139
 
135
140
  def value_or_serializable_hash(v)
@@ -4,6 +4,9 @@ require 'diesel/swagger/parameter'
4
4
  module Diesel
5
5
  module Swagger
6
6
  class Operation < Node
7
+ attr_reader :id
8
+ alias :method_name :id
9
+
7
10
  attribute :summary
8
11
  attribute :description
9
12
  attribute :external_docs, validate: true
@@ -17,6 +20,11 @@ module Diesel
17
20
  list :responses, validate: true
18
21
  list :schemes
19
22
  list :security, validate: true
23
+
24
+ def initialize(id)
25
+ super()
26
+ @id = id
27
+ end
20
28
  end
21
29
  end
22
30
  end
@@ -18,20 +18,26 @@ module Diesel
18
18
  specification.external_docs = build_node(ExternalDocs, json['externalDocs'])
19
19
  specification.schemes = json['schemes']
20
20
  specification.produces = json['produces'] || []
21
- specification.security_definitions = build_node_hash(Swagger::SecurityDefinition, json, 'securityDefinitions')
21
+ specification.security_definitions = build_node_hash(SecurityDefinition, json, 'securityDefinitions')
22
+ specification.security = (json['security'] || {}).reduce({}) do |memo, (k,v)|
23
+ memo[k] = security = Security.new(k)
24
+ security.scopes = v
25
+ memo
26
+ end
22
27
  specification.paths = build_node_hash(Path, json, 'paths') do |path, path_json|
23
28
  [:get, :put, :post, :delete, :options, :head, :patch].each do |method|
24
29
  if op_json = path_json[method.to_s]
25
- op = build_node(Operation, op_json)
30
+ op = build_node(Operation, op_json, constructor_args: [method])
26
31
  op.external_docs = build_node(ExternalDocs, op_json['externalDocs'])
27
32
  op.parameters = build_node_list(Parameter, op_json, 'parameters')
28
33
  path.send("#{method}=".to_sym, op)
29
34
  end
30
35
  end
31
36
  end
32
- specification.definitions = build_node_hash(Swagger::Definition, json, 'definitions') do |definition, def_json|
33
- definition.properties = build_node_hash(Swagger::Property, def_json, 'properties') do |prop, prop_json|
37
+ specification.definitions = build_node_hash(Definition, json, 'definitions') do |definition, def_json|
38
+ definition.properties = build_node_hash(Property, def_json, 'properties') do |prop, prop_json|
34
39
  prop.enum = prop_json['enum']
40
+ prop.items = prop_json['items']
35
41
  end
36
42
  end
37
43
  specification
@@ -39,9 +45,13 @@ module Diesel
39
45
 
40
46
  protected
41
47
 
42
- def build_node(model_class, json)
48
+ def build_node(model_class, json, options = {})
43
49
  if json
44
- model = model_class.new
50
+ model = if constructor_args = options[:constructor_args]
51
+ model_class.new(*constructor_args)
52
+ else
53
+ model_class.new
54
+ end
45
55
  model_class.attribute_names.each do |att|
46
56
  model.send("#{att}=".to_sym, json[camelize(att.to_s, false)])
47
57
  end
@@ -59,7 +69,7 @@ module Diesel
59
69
 
60
70
  def build_node_hash(model_class, json, json_hash_key)
61
71
  (json[json_hash_key] || {}).reduce({}) do |m, (k, v)|
62
- m[k] = node = build_node(model_class, v)
72
+ m[k] = node = build_node(model_class, v, constructor_args: [k])
63
73
  yield(node, v) if block_given?
64
74
  m
65
75
  end
@@ -4,18 +4,28 @@ require 'diesel/swagger/operation'
4
4
  module Diesel
5
5
  module Swagger
6
6
  class Path < Node
7
- attribute :get, validate: true
8
- attribute :put, validate: true
9
- attribute :post, validate: true
10
- attribute :delete, validate: true
11
- attribute :options, validate: true
12
- attribute :head, validate: true
13
- attribute :patch, validate: true
7
+ attr_reader :id
8
+ alias :path_name :id
9
+
10
+ REQUEST_METHODS = [:get, :put, :post, :delete, :options, :head, :patch]
11
+
12
+ REQUEST_METHODS.each do |m|
13
+ attribute m, validate: true
14
+ end
14
15
 
15
16
  list :parameters, validate: true
16
17
 
18
+ def initialize(id)
19
+ super()
20
+ @id = id
21
+ end
22
+
23
+ def operations
24
+ REQUEST_METHODS.map { |m| __send__(m) }.compact
25
+ end
26
+
17
27
  def operations_map
18
- [:get, :put, :post, :delete, :options, :head, :patch].reduce({}) do |m, method|
28
+ REQUEST_METHODS.reduce({}) do |m, method|
19
29
  if op = __send__(method)
20
30
  m[method] = op
21
31
  end
@@ -3,6 +3,13 @@ require 'diesel/swagger/data_type_field'
3
3
  module Diesel
4
4
  module Swagger
5
5
  class Property < DataTypeField
6
+ attr_reader :id
7
+
8
+ def initialize(id)
9
+ super()
10
+ @id = id
11
+ end
12
+
6
13
  end
7
14
  end
8
15
  end
@@ -0,0 +1,21 @@
1
+ require 'diesel/swagger/node'
2
+
3
+ module Diesel
4
+ module Swagger
5
+ class Security < Node
6
+ attr_reader :id
7
+
8
+ attribute :scopes
9
+
10
+ def initialize(id)
11
+ super()
12
+ @id = id
13
+ end
14
+
15
+ def serializable_hash
16
+ scopes || []
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -3,6 +3,8 @@ require 'diesel/swagger/node'
3
3
  module Diesel
4
4
  module Swagger
5
5
  class SecurityDefinition < Node
6
+ attr_reader :id
7
+
6
8
  attribute :type
7
9
  attribute :description
8
10
  attribute :name
@@ -10,6 +12,11 @@ module Diesel
10
12
  attribute :flow
11
13
  attribute :authorization_url
12
14
  attribute :token_url
15
+
16
+ def initialize(id)
17
+ super()
18
+ @id = id
19
+ end
13
20
  end
14
21
  end
15
22
  end
@@ -1,5 +1,6 @@
1
1
  require 'diesel/swagger/info'
2
2
  require 'diesel/swagger/external_docs'
3
+ require 'diesel/swagger/security'
3
4
  require 'diesel/swagger/security_definition'
4
5
  require 'diesel/swagger/path'
5
6
  require 'diesel/swagger/definition'
@@ -24,7 +25,7 @@ module Diesel
24
25
  hash :parameters, validate: true
25
26
  hash :responses, validate: true
26
27
  hash :security_definitions, validate: true
27
- hash :security
28
+ hash :security, validate: true
28
29
  end
29
30
  end
30
31
  end
@@ -1,3 +1,3 @@
1
1
  module Diesel
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -4,12 +4,12 @@ require 'diesel/swagger/parser'
4
4
  describe Diesel::Swagger::Parser do
5
5
  subject { Diesel::Swagger::Parser }
6
6
 
7
- let(:specification_json) do
8
- File.read(File.join(File.dirname(__FILE__), '..', '..', 'files', 'pivotal_tracker.json'))
7
+ def load_spec(name)
8
+ File.read(File.join(File.dirname(__FILE__), '..', '..', 'files', "#{name}.json"))
9
9
  end
10
10
 
11
- it "should parse a diesel specification" do
12
- specification = Diesel::Swagger::Parser.new.parse(specification_json)
11
+ it "should parse a swagger specification" do
12
+ specification = Diesel::Swagger::Parser.new.parse(load_spec('pivotal_tracker'))
13
13
  expect(specification).to_not be_nil
14
14
 
15
15
  expect(specification.host).to eq "www.pivotaltracker.com"
@@ -23,9 +23,12 @@ describe Diesel::Swagger::Parser do
23
23
  api_token = specification.security_definitions['apiToken']
24
24
  expect(api_token).to_not be_nil
25
25
  expect(api_token.type).to eq "apiKey"
26
- expect(api_token.in).to eq "header"
26
+ expect(api_token.in).to eq :header
27
27
  expect(api_token.name).to eq "X-TrackerToken"
28
28
 
29
+ security = specification.security['apiToken']
30
+ expect(security).to_not be_nil
31
+
29
32
  expect(specification.produces).to include "application/json"
30
33
 
31
34
  expect(specification.paths.count).to eq 1
@@ -48,7 +51,7 @@ describe Diesel::Swagger::Parser do
48
51
  param2 = path.post.parameters[1]
49
52
  expect(param2).to_not be_nil
50
53
  expect(param2.in).to eq :body
51
- expect(param2.name).to eq "body"
54
+ expect(param2.name).to eq "story"
52
55
  expect(param2).to be_required
53
56
  expect(param2.schema).to eq "NewStory"
54
57
 
@@ -77,4 +80,14 @@ describe Diesel::Swagger::Parser do
77
80
  "unscheduled"
78
81
  ]
79
82
  end
83
+
84
+ it "should parse a swagger specification with an array of schema objects" do
85
+ specification = Diesel::Swagger::Parser.new.parse(load_spec('slack'))
86
+ payload = specification.definitions["Payload"]
87
+
88
+ attachments_prop = payload.properties['attachments']
89
+ expect(attachments_prop.type).to eq :array
90
+ expect(attachments_prop.items.count).to eq 1
91
+ expect(attachments_prop.items["$ref"]).to eq '#/definitions/Attachment'
92
+ end
80
93
  end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+ require 'diesel/swagger/specification'
3
+
4
+ describe Diesel::Swagger::Specification do
5
+
6
+ it "should serialize security node as key and scopes" do
7
+ spec = described_class.new
8
+
9
+ security = Diesel::Swagger::Security.new('oauth')
10
+ security.scopes = ['email']
11
+ spec.security = { 'oauth' => security }
12
+
13
+ hash = spec.serializable_hash
14
+ security_hash = hash['security']
15
+ expect(security_hash).to_not be_nil
16
+ scopes = security_hash['oauth']
17
+ expect(scopes).to eq ['email']
18
+ end
19
+ end
data/spec/diesel_spec.rb CHANGED
@@ -40,4 +40,38 @@ describe Diesel do
40
40
  expect(results.response.code).to eq "200"
41
41
  end
42
42
  end
43
+
44
+ it "should be able to build a Slack API client" do
45
+ Slack = load_api('slack')
46
+ client = Slack.new
47
+ client.logger = Logger.new(STDOUT)
48
+ client.logger.level = Logger::DEBUG
49
+
50
+ VCR.use_cassette('slack') do
51
+ results = client.post_message(path: 'abcd/efgh/ijkl',
52
+ payload: {
53
+ text: 'Testing',
54
+ username: 'TestBot',
55
+ attachments: [
56
+ {
57
+ fallback: "test fallback text",
58
+ text: "test text",
59
+ pretext: "test pretext",
60
+ fields: [
61
+ {
62
+ title: "test field 1",
63
+ value: "test value 1"
64
+ },
65
+ {
66
+ title: "test field 2",
67
+ value: "test value 2"
68
+ }
69
+ ]
70
+ }
71
+ ]
72
+ })
73
+ expect(results.response.code).to eq "200"
74
+ expect(results.parsed_response).to eq "ok"
75
+ end
76
+ end
43
77
  end
@@ -0,0 +1,88 @@
1
+ {
2
+ "swagger": "2.0",
3
+
4
+ "info": {
5
+ "title": "Slack",
6
+ "description": "Slack Incoming Webhook",
7
+ "version": "1"
8
+ },
9
+
10
+ "host": "hooks.slack.com",
11
+
12
+ "basePath": "/services",
13
+
14
+ "schemes": ["https"],
15
+
16
+ "produces": ["application/json"],
17
+
18
+ "paths": {
19
+ "/{path}": {
20
+ "post": {
21
+ "summary": "Post message into Slack",
22
+ "operationId": "postMessage",
23
+ "parameters": [
24
+ {
25
+ "name": "path",
26
+ "in": "path",
27
+ "required": true,
28
+ "type": "string"
29
+ },
30
+ {
31
+ "name": "payload",
32
+ "in": "body",
33
+ "required": true,
34
+ "schema": "Payload"
35
+ }
36
+ ]
37
+ }
38
+ }
39
+ },
40
+
41
+ "definitions": {
42
+ "Payload": {
43
+ "title": "Payload",
44
+ "type": "object",
45
+ "required": [ "text" ],
46
+ "properties": {
47
+ "text": { "type": "string" },
48
+ "username": { "type": "string" },
49
+ "icon_url": { "type": "string" },
50
+ "icon_emoji": { "type": "string" },
51
+ "channel": { "type": "string" },
52
+ "attachments": {
53
+ "type": "array",
54
+ "items": {
55
+ "$ref": "#/definitions/Attachment"
56
+ }
57
+ }
58
+ }
59
+ },
60
+ "Attachment": {
61
+ "title": "Attachment",
62
+ "type": "object",
63
+ "required": ["fallback"],
64
+ "properties": {
65
+ "fallback": { "type": "string" },
66
+ "text": { "type": "string" },
67
+ "pretext": { "type": "string" },
68
+ "color": { "type": "string" },
69
+ "fields": {
70
+ "type": "array",
71
+ "items": {
72
+ "$ref": "#/definitions/AttachmentField"
73
+ }
74
+ }
75
+ },
76
+ "AttachmentField": {
77
+ "title": "Attachment Field",
78
+ "type": "object",
79
+ "required": ["title"],
80
+ "properties": {
81
+ "title": { "type": "string" },
82
+ "value": { "type": "string" },
83
+ "short": { "type": "boolean" }
84
+ }
85
+ }
86
+ }
87
+ }
88
+ }
@@ -0,0 +1,43 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://hooks.slack.com/services/abcd/efgh/ijkl
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"text":"Testing","username":"TestBot","attachments":[{"fallback":"test
9
+ fallback text","text":"test text","pretext":"test pretext","fields":[{"title":"test
10
+ field 1","value":"test value 1"},{"title":"test field 2","value":"test value
11
+ 2"}]}]}'
12
+ headers:
13
+ Content-Type:
14
+ - application/json
15
+ response:
16
+ status:
17
+ code: 200
18
+ message: OK
19
+ headers:
20
+ Access-Control-Allow-Origin:
21
+ - "*"
22
+ Content-Type:
23
+ - text/html
24
+ Date:
25
+ - Sun, 04 Jan 2015 21:21:29 GMT
26
+ Server:
27
+ - Apache
28
+ Strict-Transport-Security:
29
+ - max-age=31536000; includeSubDomains; preload
30
+ Vary:
31
+ - Accept-Encoding
32
+ X-Frame-Options:
33
+ - SAMEORIGIN
34
+ Content-Length:
35
+ - '2'
36
+ Connection:
37
+ - keep-alive
38
+ body:
39
+ encoding: UTF-8
40
+ string: ok
41
+ http_version:
42
+ recorded_at: Sun, 04 Jan 2015 21:21:29 GMT
43
+ recorded_with: VCR 2.9.3
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diesel-api-dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Calvin Yu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-04 00:00:00.000000000 Z
11
+ date: 2015-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -120,9 +120,7 @@ files:
120
120
  - LICENSE
121
121
  - README.md
122
122
  - Rakefile
123
- - apis/slack.rb
124
123
  - diesel.gemspec
125
- - examples/post_slack_message.rb
126
124
  - lib/diesel.rb
127
125
  - lib/diesel/api_base.rb
128
126
  - lib/diesel/api_builder.rb
@@ -131,6 +129,7 @@ files:
131
129
  - lib/diesel/data_model.rb
132
130
  - lib/diesel/endpoint.rb
133
131
  - lib/diesel/middleware/auth/api_key.rb
132
+ - lib/diesel/middleware/auth/oauth2.rb
134
133
  - lib/diesel/middleware/debug.rb
135
134
  - lib/diesel/middleware/set_body_parameter.rb
136
135
  - lib/diesel/middleware/set_header.rb
@@ -150,17 +149,21 @@ files:
150
149
  - lib/diesel/swagger/parser.rb
151
150
  - lib/diesel/swagger/path.rb
152
151
  - lib/diesel/swagger/property.rb
152
+ - lib/diesel/swagger/security.rb
153
153
  - lib/diesel/swagger/security_definition.rb
154
154
  - lib/diesel/swagger/specification.rb
155
155
  - lib/diesel/utils/inflections.rb
156
156
  - lib/diesel/version.rb
157
157
  - spec/diesel/api_builder_spec.rb
158
158
  - spec/diesel/swagger/parser_spec.rb
159
+ - spec/diesel/swagger/specification_spec.rb
159
160
  - spec/diesel_spec.rb
160
161
  - spec/files/honeybadger.json
161
162
  - spec/files/pivotal_tracker.json
163
+ - spec/files/slack.json
162
164
  - spec/fixtures/vcr_cassettes/honeybadger.yml
163
165
  - spec/fixtures/vcr_cassettes/pivotal_tracker_create_story.yml
166
+ - spec/fixtures/vcr_cassettes/slack.yml
164
167
  - spec/spec_helper.rb
165
168
  homepage: http://github.com/cyu/diesel
166
169
  licenses:
@@ -182,16 +185,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
185
  version: '0'
183
186
  requirements: []
184
187
  rubyforge_project:
185
- rubygems_version: 2.2.2
188
+ rubygems_version: 2.4.5
186
189
  signing_key:
187
190
  specification_version: 4
188
191
  summary: Create API Clients From an DSL
189
192
  test_files:
190
193
  - spec/diesel/api_builder_spec.rb
191
194
  - spec/diesel/swagger/parser_spec.rb
195
+ - spec/diesel/swagger/specification_spec.rb
192
196
  - spec/diesel_spec.rb
193
197
  - spec/files/honeybadger.json
194
198
  - spec/files/pivotal_tracker.json
199
+ - spec/files/slack.json
195
200
  - spec/fixtures/vcr_cassettes/honeybadger.yml
196
201
  - spec/fixtures/vcr_cassettes/pivotal_tracker_create_story.yml
202
+ - spec/fixtures/vcr_cassettes/slack.yml
197
203
  - spec/spec_helper.rb
data/apis/slack.rb DELETED
@@ -1,36 +0,0 @@
1
- apis do
2
- description "Slack"
3
- api_version "1"
4
- base_path "https://scoutmob.slack.com/services/hooks"
5
-
6
- api_key "token" do
7
- nickname :api_token
8
- pass_as :query_parameter
9
- end
10
-
11
- header "Content-Type" => "application/json"
12
-
13
- resource "incoming-webhook" do
14
- description "Incoming Webhook"
15
-
16
- operation :send_message do
17
- reference_url "https://my.slack.com/services/new/incoming-webhook"
18
- method :post
19
-
20
- body "payload" do
21
- data_type "Payload"
22
- end
23
- end
24
- end
25
-
26
- complex_type "Payload" do
27
- required :text
28
- property :text
29
- property :channel
30
- property :username
31
- property :icon_url
32
- property :icon_emoji
33
- end
34
-
35
- end
36
-
@@ -1,8 +0,0 @@
1
- require 'diesel'
2
- require 'logger'
3
-
4
- Slack = Diesel.load_api 'apis/slack'
5
- api = Slack.new
6
- api.logger = Logger.new STDOUT
7
- api.api_token = YOUR_API_TOKEN
8
- puts api.send_message(payload: {text: 'testing', channel: '#developers', username: 'calvin'})