ciscospark-ruby 0.2.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b7cc5c9744dcded28cf282ce413e08c7ce033bac
4
+ data.tar.gz: 196c82747e01a20396facc15a83635ec3f7869e8
5
+ SHA512:
6
+ metadata.gz: b4effe364b9cc5cbbdffcaf4f4a7010326895bdd6ec55be753db95483cb199e38a4b72825de53edba38aaf48bfacea27cb349a724f3b85aec093750768556728
7
+ data.tar.gz: 8325873ec69292db95f81218400cc0c572ebc2eb9b0b0da2ce5283b2bca70fd6801b5e7dd53b785147ba05304200c577450504e25192d24937b421bc03be8c28
@@ -0,0 +1,183 @@
1
+ require "httparty"
2
+
3
+ class Spark
4
+
5
+ #People API
6
+
7
+ def self.get_people(token)
8
+ response = HTTParty.get("https://api.ciscospark.com/v1/people", headers: {"Authorization" => "Bearer " + token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'})
9
+ return response
10
+ end
11
+
12
+ def self.get_person(token, person_id)
13
+ response = HTTParty.get("https://api.ciscospark.com/v1/people/" + person_id.to_s, headers: {"Authorization" => "Bearer " + token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'})
14
+ return response
15
+ end
16
+
17
+ def self.get_me(token)
18
+ response = HTTParty.get("https://api.ciscospark.com/v1/people/me", headers: {"Authorization" => "Bearer " + token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'})
19
+ return response
20
+ end
21
+
22
+ #Rooms API
23
+
24
+ def self.get_rooms(token)
25
+ response = HTTParty.get("https://api.ciscospark.com/v1/rooms", headers: {"Authorization" => "Bearer " + token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'})
26
+ return response
27
+ end
28
+
29
+ def self.post_room(token, title,team_id=nil)
30
+ if team_id.nil?
31
+ response = HTTParty.post("https://api.ciscospark.com/v1/rooms", headers: {"Authorization" => "Bearer " + token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'}, :body => { "title" => title}.to_json)
32
+ else
33
+ response = HTTParty.post("https://api.ciscospark.com/v1/rooms", headers: {"Authorization" => "Bearer " + token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'}, :body => { "title" => title, "teamId" => team_id}.to_json)
34
+ end
35
+ return response
36
+ end
37
+
38
+ def self.get_room(token, room_id)
39
+ @options = { headers: {"Authorization" => "Bearer " + token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'}, query: {showSipAddress: true} }
40
+ response = HTTParty.get("https://api.ciscospark.com/v1/rooms/" + room_id.to_s, @options)
41
+ return response
42
+ end
43
+
44
+ def self.update_room(token, room_id, title, team_id=nil)
45
+ if team_id.nil?
46
+ response = HTTParty.put("https://api.ciscospark.com/v1/rooms/" + room_id.to_s, headers: {"Authorization" => "Bearer " + token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'}, :body => { "title" => title}.to_json)
47
+ else
48
+ response = HTTParty.put("https://api.ciscospark.com/v1/rooms/" + room_id.to_s, headers: {"Authorization" => "Bearer " + token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'}, :body => { "title" => title, "teamId" => team_id}.to_json)
49
+ end
50
+ return response
51
+ end
52
+
53
+ def self.delete_room(token,id)
54
+ response = HTTParty.delete("https://api.ciscospark.com/v1/rooms/" + id.to_s, headers: {"Authorization" => "Bearer " + token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'})
55
+ return response
56
+ end
57
+
58
+
59
+ #Membership API
60
+
61
+ def self.get_memberships(token, room_id)
62
+ @options = { headers: {"Authorization" => "Bearer " + token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'}, query: {roomId: room_id} }
63
+ response = HTTParty.get("https://api.ciscospark.com/v1/memberships", @options)
64
+ return response
65
+ end
66
+
67
+ def self.post_membership(token, room_id, email, moderator=nil)
68
+ response = HTTParty.post("https://api.ciscospark.com/v1/memberships", headers: {"Authorization" => "Bearer " + token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'}, :body => { "roomId" => room_id, "personEmail" => email}.to_json)
69
+ return response
70
+ end
71
+
72
+ def self.get_membership(token, membership_id)
73
+ @options = { headers: {"Authorization" => "Bearer " + token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'}, query: {roomId: room_id} }
74
+ response = HTTParty.get("https://api.ciscospark.com/v1/memberships/" + membership_id.to_s, @options)
75
+ return response
76
+ end
77
+
78
+ def self.update_membership(token, membership_id, room_id, email, moderator=nil)
79
+ response = HTTParty.put("https://api.ciscospark.com/v1/memberships/" + membership_id.to_s, headers: {"Authorization" => "Bearer " + token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'}, :body => { "roomId" => room_id, "personEmail" => email}.to_json)
80
+ return response
81
+ end
82
+
83
+ def self.delete_membership(token, id)
84
+ response = HTTParty.delete("https://api.ciscospark.com/v1/memberships/" + id.to_s, headers: {"Authorization" => "Bearer " + token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'})
85
+ return response
86
+ end
87
+
88
+
89
+ #Messages API
90
+
91
+ def self.get_messages(token,room_id,max=10,beforeid=nil)
92
+ if (beforeid.nil?)
93
+ @options = { headers: {"Authorization" => "Bearer " + token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'}, query: {roomId: room_id, max: max} }
94
+ response = HTTParty.get("https://api.ciscospark.com/v1/messages", @options)
95
+ else
96
+ @options = { headers: {"Authorization" => "Bearer " + token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'}, query: {roomId: room_id, max: max, beforeMessage: beforeid} }
97
+ response = HTTParty.get("https://api.ciscospark.com/v1/messages", @options)
98
+ end
99
+ return response
100
+ end
101
+
102
+ def self.get_message(token, message_id)
103
+ response = HTTParty.get("https://api.ciscospark.com/v1/messages/" + message_id, headers: {"Authorization" => "Bearer " + token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'})
104
+ return response
105
+ end
106
+
107
+ def self.post_message(token, room_id, message)
108
+ response = HTTParty.post("https://api.ciscospark.com/v1/messages", headers: {"Authorization" => "Bearer " + token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'}, :body => { "roomId" => room_id,
109
+ "text" => message}.to_json)
110
+ return response
111
+ end
112
+
113
+ def self.post_message_file(token, room_id, message, file)
114
+ response = HTTParty.post("https://api.ciscospark.com/v1/messages", headers: {"Authorization" => "Bearer " + token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'}, :body => { "roomId" => room_id,
115
+ "text" => message, "file" => file}.to_json)
116
+ return response
117
+ end
118
+
119
+ def self.delete_message(token,id)
120
+ response = HTTParty.delete("https://api.ciscospark.com/v1/messages/" + id.to_s, headers: {"Authorization" => "Bearer " + token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'})
121
+ return response
122
+ end
123
+
124
+ #Teams API
125
+
126
+ def self.get_teams(token)
127
+ response = HTTParty.get("https://api.ciscospark.com/v1/teams", headers: {"Authorization" => "Bearer " + token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'})
128
+ return response
129
+ end
130
+
131
+ def self.post_team(token, name)
132
+ response = HTTParty.post("https://api.ciscospark.com/v1/teams", headers: {"Authorization" => "Bearer " + token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'}, :body => { "name" => name}.to_json)
133
+ return response
134
+ end
135
+
136
+ def self.get_team(token, team_id)
137
+ response = HTTParty.get("https://api.ciscospark.com/v1/teams/" + team_id.to_s, headers: {"Authorization" => "Bearer " + token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'})
138
+ return response
139
+ end
140
+
141
+ def self.update_team(token, name)
142
+ response = HTTParty.put("https://api.ciscospark.com/v1/teams/" + team_id.to_s, headers: {"Authorization" => "Bearer " + token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'}, :body => { "name" => name}.to_json)
143
+ return response
144
+ end
145
+
146
+ #Team Membership API
147
+
148
+ def self.post_team_membership(token, team_id, person_email)
149
+ response = HTTParty.post("https://api.ciscospark.com/v1/team/memberships", headers: {"Authorization" => "Bearer " + token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'}, :body => { "teamId" => team_id,
150
+ "personEmail" => person_email}.to_json)
151
+ return response
152
+ end
153
+
154
+ #Webhooks API
155
+
156
+ def self.get_webhooks(token)
157
+ response = HTTParty.get("https://api.ciscospark.com/v1/webhooks", headers: {"Authorization" => "Bearer " + token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'})
158
+ return response
159
+ end
160
+
161
+ def self.post_webhook(token, resource, event, resource_id, url, name)
162
+ response = HTTParty.post("https://api.ciscospark.com/v1/webhooks", headers: {"Authorization" => "Bearer " + token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'}, :body => { "resource" => resource, "event" => event, "filter" => resource_id,
163
+ "targetUrl" => url, "name" => name, }.to_json)
164
+ return response
165
+ end
166
+
167
+ def self.get_webhook(token,id)
168
+ response = HTTParty.get("https://api.ciscospark.com/v1/webhooks" + id.to_s, headers: {"Authorization" => "Bearer " + token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'})
169
+ return response
170
+ end
171
+
172
+ def self.update_webhook(token, id, resource, event, resource_id, url, name)
173
+ response = HTTParty.put("https://api.ciscospark.com/v1/webhooks" + id.to_s, headers: {"Authorization" => "Bearer " + token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'}, :body => { "resource" => resource, "event" => event, "filter" => resource_id,
174
+ "targetUrl" => url, "name" => name, }.to_json)
175
+ return response
176
+ end
177
+
178
+ def self.delete_webhook(token,id)
179
+ response = HTTParty.delete("https://api.ciscospark.com/v1/webhooks/" + id.to_s, headers: {"Authorization" => "Bearer " + token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'})
180
+ return response
181
+ end
182
+
183
+ end
@@ -0,0 +1,28 @@
1
+ $LOAD_PATH.unshift File.expand_path("..", __FILE__)
2
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
3
+
4
+ if RUBY_VERSION >= "1.9"
5
+ require "simplecov"
6
+ require "coveralls"
7
+
8
+ SimpleCov.formatters = [SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter]
9
+
10
+ SimpleCov.start do
11
+ minimum_coverage(78.48)
12
+ end
13
+ end
14
+
15
+ require "rspec"
16
+ require "rack/test"
17
+ require "webmock/rspec"
18
+ require "omniauth"
19
+ require "omniauth-oauth2"
20
+
21
+ RSpec.configure do |config|
22
+ config.expect_with :rspec do |c|
23
+ c.syntax = :expect
24
+ end
25
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
26
+ config.include Rack::Test::Methods
27
+ config.include WebMock::API
28
+ end
@@ -0,0 +1,107 @@
1
+ require "helper"
2
+
3
+ describe OmniAuth::Strategies::OAuth2 do
4
+ def app
5
+ lambda do |_env|
6
+ [200, {}, ["Hello."]]
7
+ end
8
+ end
9
+ let(:fresh_strategy) { Class.new(OmniAuth::Strategies::OAuth2) }
10
+
11
+ before do
12
+ OmniAuth.config.test_mode = true
13
+ end
14
+
15
+ after do
16
+ OmniAuth.config.test_mode = false
17
+ end
18
+
19
+ describe "Subclassing Behavior" do
20
+ subject { fresh_strategy }
21
+
22
+ it "performs the OmniAuth::Strategy included hook" do
23
+ expect(OmniAuth.strategies).to include(OmniAuth::Strategies::OAuth2)
24
+ expect(OmniAuth.strategies).to include(subject)
25
+ end
26
+ end
27
+
28
+ describe "#client" do
29
+ subject { fresh_strategy }
30
+
31
+ it "is initialized with symbolized client_options" do
32
+ instance = subject.new(app, :client_options => {"authorize_url" => "https://example.com"})
33
+ expect(instance.client.options[:authorize_url]).to eq("https://example.com")
34
+ end
35
+
36
+ it "sets ssl options as connection options" do
37
+ instance = subject.new(app, :client_options => {"ssl" => {"ca_path" => "foo"}})
38
+ expect(instance.client.options[:connection_opts][:ssl]).to eq(:ca_path => "foo")
39
+ end
40
+ end
41
+
42
+ describe "#authorize_params" do
43
+ subject { fresh_strategy }
44
+
45
+ it "includes any authorize params passed in the :authorize_params option" do
46
+ instance = subject.new("abc", "def", :authorize_params => {:foo => "bar", :baz => "zip"})
47
+ expect(instance.authorize_params["foo"]).to eq("bar")
48
+ expect(instance.authorize_params["baz"]).to eq("zip")
49
+ end
50
+
51
+ it "includes top-level options that are marked as :authorize_options" do
52
+ instance = subject.new("abc", "def", :authorize_options => [:scope, :foo, :state], :scope => "bar", :foo => "baz")
53
+ expect(instance.authorize_params["scope"]).to eq("bar")
54
+ expect(instance.authorize_params["foo"]).to eq("baz")
55
+ end
56
+
57
+ it "includes random state in the authorize params" do
58
+ instance = subject.new("abc", "def")
59
+ expect(instance.authorize_params.keys).to eq(["state"])
60
+ expect(instance.session["omniauth.state"]).not_to be_empty
61
+ end
62
+ end
63
+
64
+ describe "#token_params" do
65
+ subject { fresh_strategy }
66
+
67
+ it "includes any authorize params passed in the :authorize_params option" do
68
+ instance = subject.new("abc", "def", :token_params => {:foo => "bar", :baz => "zip"})
69
+ expect(instance.token_params).to eq("foo" => "bar", "baz" => "zip")
70
+ end
71
+
72
+ it "includes top-level options that are marked as :authorize_options" do
73
+ instance = subject.new("abc", "def", :token_options => [:scope, :foo], :scope => "bar", :foo => "baz")
74
+ expect(instance.token_params).to eq("scope" => "bar", "foo" => "baz")
75
+ end
76
+ end
77
+
78
+ describe "#callback_phase" do
79
+ subject { fresh_strategy }
80
+ it "calls fail with the client error received" do
81
+ instance = subject.new("abc", "def")
82
+ allow(instance).to receive(:request) do
83
+ double("Request", :params => {"error_reason" => "user_denied", "error" => "access_denied"})
84
+ end
85
+
86
+ expect(instance).to receive(:fail!).with("user_denied", anything)
87
+ instance.callback_phase
88
+ end
89
+ end
90
+ end
91
+
92
+ describe OmniAuth::Strategies::OAuth2::CallbackError do
93
+ let(:error) { Class.new(OmniAuth::Strategies::OAuth2::CallbackError) }
94
+ describe "#message" do
95
+ subject { error }
96
+ it "includes all of the attributes" do
97
+ instance = subject.new("error", "description", "uri")
98
+ expect(instance.message).to match(/error/)
99
+ expect(instance.message).to match(/description/)
100
+ expect(instance.message).to match(/uri/)
101
+ end
102
+ it "includes all of the attributes" do
103
+ instance = subject.new(nil, :symbol)
104
+ expect(instance.message).to eq("symbol")
105
+ end
106
+ end
107
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ciscospark-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Chad Stachowicz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
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.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ description: A REST API Toolkit for Cisco Spark
42
+ email:
43
+ - cstachowicz@cloverhound.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/ciscospark.rb
49
+ - spec/helper.rb
50
+ - spec/omniauth/strategies/oauth2_spec.rb
51
+ homepage: https://github.com/cloverhound/ciscospark-ruby
52
+ licenses:
53
+ - MIT
54
+ metadata: {}
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 2.4.6
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: A REST API Toolkit for Cisco Spark
75
+ test_files:
76
+ - spec/helper.rb
77
+ - spec/omniauth/strategies/oauth2_spec.rb
78
+ has_rdoc: