microsoft-live-simple 0.1.0

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: c5e1280aafa1215917a6d17acb0b7f66e0e9e0a0
4
+ data.tar.gz: 92ff5d4fd8a8f52433fbdc437122ff26378c19c9
5
+ SHA512:
6
+ metadata.gz: 1d3211bef0097183cba294db12a7e027918d680350c71a6421001181fd3a51870dbbf75fa0957d2483e43d0f3b95f2c3a40a907b8419290dd732dc3d9dd8e4eb
7
+ data.tar.gz: 943ffe7ead74a9e023a249cd877e2cba421d06e8e38123bae5e6dee19162ba425b113171e7425eb4b865731af2fa794a8ed46a87a4256780de87284e735c2530
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ coverage/
2
+ .byebug_history
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format doc
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ ---
2
+
3
+ language: ruby
4
+ rvm: 2.1.0
5
+ before_install:
6
+ - gem install bundler --no-ri --no-rdoc
7
+ script: CODECLIMATE_REPO_TOKEN=e8e06f8d90a3cede40689f57ffa00ff3eb388b1b0d7d0d4c79796acf94908242 bundle && bundle exec rspec
8
+ addons:
9
+ code_climate:
10
+ repo_token: e8e06f8d90a3cede40689f57ffa00ff3eb388b1b0d7d0d4c79796acf94908242
11
+
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+
2
+ source "https://rubygems.org"
3
+
4
+ gem 'codeclimate-test-reporter', group: :test, require: nil
5
+
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,94 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ microsoft-live-rest-client (0.1.0)
5
+ httparty
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (4.2.5.1)
11
+ i18n (~> 0.7)
12
+ json (~> 1.7, >= 1.7.7)
13
+ minitest (~> 5.1)
14
+ thread_safe (~> 0.3, >= 0.3.4)
15
+ tzinfo (~> 1.1)
16
+ addressable (2.4.0)
17
+ ast (2.2.0)
18
+ byebug (8.2.2)
19
+ codeclimate-test-reporter (0.4.8)
20
+ simplecov (>= 0.7.1, < 1.0.0)
21
+ crack (0.4.3)
22
+ safe_yaml (~> 1.0.0)
23
+ diff-lcs (1.2.5)
24
+ docile (1.1.5)
25
+ faker (1.6.3)
26
+ i18n (~> 0.5)
27
+ hashdiff (0.3.0)
28
+ httparty (0.13.7)
29
+ json (~> 1.8)
30
+ multi_xml (>= 0.5.2)
31
+ i18n (0.7.0)
32
+ json (1.8.3)
33
+ minitest (5.8.4)
34
+ multi_xml (0.5.5)
35
+ parser (2.3.0.6)
36
+ ast (~> 2.2)
37
+ powerpack (0.1.1)
38
+ rainbow (2.1.0)
39
+ rake (10.5.0)
40
+ rspec (3.4.0)
41
+ rspec-core (~> 3.4.0)
42
+ rspec-expectations (~> 3.4.0)
43
+ rspec-mocks (~> 3.4.0)
44
+ rspec-core (3.4.3)
45
+ rspec-support (~> 3.4.0)
46
+ rspec-expectations (3.4.0)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.4.0)
49
+ rspec-mocks (3.4.1)
50
+ diff-lcs (>= 1.2.0, < 2.0)
51
+ rspec-support (~> 3.4.0)
52
+ rspec-support (3.4.1)
53
+ rubocop (0.37.2)
54
+ parser (>= 2.3.0.4, < 3.0)
55
+ powerpack (~> 0.1)
56
+ rainbow (>= 1.99.1, < 3.0)
57
+ ruby-progressbar (~> 1.7)
58
+ unicode-display_width (~> 0.3)
59
+ ruby-progressbar (1.7.5)
60
+ safe_yaml (1.0.4)
61
+ shoulda-matchers (3.1.1)
62
+ activesupport (>= 4.0.0)
63
+ simplecov (0.11.2)
64
+ docile (~> 1.1.0)
65
+ json (~> 1.8)
66
+ simplecov-html (~> 0.10.0)
67
+ simplecov-html (0.10.0)
68
+ thread_safe (0.3.5)
69
+ tzinfo (1.2.2)
70
+ thread_safe (~> 0.1)
71
+ unicode-display_width (0.3.1)
72
+ webmock (1.24.1)
73
+ addressable (>= 2.3.6)
74
+ crack (>= 0.3.2)
75
+ hashdiff
76
+
77
+ PLATFORMS
78
+ ruby
79
+
80
+ DEPENDENCIES
81
+ bundler (~> 1.7)
82
+ byebug
83
+ codeclimate-test-reporter
84
+ faker
85
+ microsoft-live-rest-client!
86
+ rake (~> 10.0)
87
+ rspec
88
+ rubocop
89
+ shoulda-matchers
90
+ simplecov
91
+ webmock
92
+
93
+ BUNDLED WITH
94
+ 1.11.2
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ [![Build Status](https://travis-ci.org/jdrago999/microsoft-live-simple.svg?branch=master)](https://travis-ci.org/jdrago999/microsoft-live-simple)
2
+ [![Code Climate](https://codeclimate.com/github/jdrago999/microsoft-live-simple/badges/gpa.svg)](https://codeclimate.com/github/jdrago999/microsoft-live-simple)
3
+ [![Test Coverage](https://codeclimate.com/github/jdrago999/microsoft-live-simple/badges/coverage.svg)](https://codeclimate.com/github/jdrago999/microsoft-live-simple/coverage)
4
+ [![Issue Count](https://codeclimate.com/github/jdrago999/microsoft-live-simple/badges/issue_count.svg)](https://codeclimate.com/github/jdrago999/microsoft-live-simple)
5
+
6
+ # microsoft-live-simple
7
+
8
+ ## INSTALLATION
9
+
10
+ In your `Gemfile`:
11
+
12
+ ```ruby
13
+ gem 'microsoft-live-simple', github: 'jdrago999/microsoft-live-simple'
14
+ ```
15
+
16
+ ## DESCRIPTION
17
+
18
+ A simple client to the Microsoft "Live" REST API.
19
+
20
+ Designed to worth with the OAuth2.0 tokens retrieved by https://github.com/jdrago999/omniauth-microsoft-live
21
+
22
+ ## RATIONALE
23
+
24
+ I couldn't find one that already existed.
25
+
26
+ ## SYNOPSIS
27
+
28
+ ```ruby
29
+ require 'microsoft-live'
30
+
31
+ MicrosoftLive.configure do |config|
32
+ config.client_id = ENV['CLIENT_ID']
33
+ config.client_secret = ENV['CLIENT_SECRET']
34
+ config.redirect_uri = ENV['REDIRECT_URI']
35
+ end
36
+
37
+ client = MicrosoftLive::Client.new(
38
+ access_token: '...',
39
+ refresh_token: '...',
40
+ expires_at: ...
41
+ )
42
+
43
+ # NOTE: Your token is automatically refreshed when the old one expires.
44
+
45
+ result = client.contacts
46
+ contacts = [ ]
47
+ loop do
48
+ break unless result.items
49
+
50
+ all_contacts += result.items
51
+ result = result.next_page
52
+ end
53
+
54
+ # Contact can reference a user:
55
+ user = contacts.first.user
56
+ ```
57
+
58
+ ## LICENSE
59
+
60
+ This software is released under the Apache License, version 2.0. A copy of the license is included with this software.
61
+
62
+ ## SEE ALSO
63
+
64
+ * https://msdn.microsoft.com/en-us/library/hh243648.aspx
65
+ * https://msdn.microsoft.com/en-us/library/hh243649.aspx#refresh_rest
66
+
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ include Rake::DSL
2
+
3
+ task :environment do
4
+ require 'bundler/setup'
5
+ lib = File.expand_path('../lib', __FILE__)
6
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
7
+ require 'microsoft-live/simple'
8
+ end
9
+
10
+ desc 'enter a REPL console within this project environment'
11
+ task :console => :environment do
12
+ require 'irb'
13
+ require 'irb/completion'
14
+ ARGV.clear
15
+ IRB.start
16
+ end
@@ -0,0 +1,29 @@
1
+
2
+ module MicrosoftLive
3
+ class Collector
4
+ include HTTParty
5
+ attr_accessor :simple, :path, :limit, :offset, :result, :page_size, :item_class
6
+ base_uri 'https://login.live.com/'
7
+
8
+ def initialize(simple:, path:, limit:, offset:, page_size: 50, item_class:)
9
+ self.simple = simple
10
+ self.path = path
11
+ self.limit = limit
12
+ self.offset = offset
13
+ self.page_size = page_size
14
+ self.item_class = item_class
15
+ end
16
+
17
+ def items
18
+ response = simple.get_collection(url: path, limit: limit, offset: offset)
19
+ response[:data].map do |item|
20
+ item_class.new(data: item, simple: simple)
21
+ end
22
+ end
23
+
24
+ def next_page
25
+ self.offset += page_size
26
+ items
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+
2
+ module MicrosoftLive
3
+ class Contact
4
+ attr_accessor :id,
5
+ :first_name,
6
+ :last_name,
7
+ :name,
8
+ :is_friend,
9
+ :is_favorite,
10
+ :user_id,
11
+ :email_hashes,
12
+ :updated_time,
13
+ :birth_day,
14
+ :birth_month,
15
+ :simple
16
+
17
+ def initialize(data: {}, simple:)
18
+ data.each do |key,val|
19
+ self.send "#{key}=", val
20
+ end
21
+ self.simple = simple
22
+ end
23
+
24
+ def user
25
+ return unless user_id
26
+ simple.user(user_id)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,103 @@
1
+
2
+ require 'httparty'
3
+ require 'microsoft-live/collector'
4
+ require 'microsoft-live/contact'
5
+ require 'microsoft-live/user'
6
+ module MicrosoftLive
7
+ class RenewTokenError < StandardError; end
8
+ class ApiError < StandardError; end
9
+ class Simple
10
+ include HTTParty
11
+ attr_accessor :client_id, :client_secret, :token, :refresh_token, :expires_at, :redirect_uri
12
+ base_uri 'https://login.live.com/'
13
+
14
+ def initialize(token:, refresh_token:, expires_at:)
15
+ self.client_id = MicrosoftLive.config.client_id
16
+ self.client_secret = MicrosoftLive.config.client_secret
17
+ self.redirect_uri = MicrosoftLive.config.redirect_uri
18
+ self.token = token
19
+ self.refresh_token = refresh_token
20
+ self.expires_at = expires_at
21
+ end
22
+
23
+ def contacts
24
+ ::MicrosoftLive::Collector.new(
25
+ simple: self,
26
+ path: '/me/contacts',
27
+ offset: 0,
28
+ limit: 50,
29
+ item_class: ::MicrosoftLive::Contact
30
+ )
31
+ end
32
+
33
+ def user(user_id)
34
+ data = get_object(url: user_id)
35
+ ::MicrosoftLive::User.new(data: data, simple: self)
36
+ end
37
+
38
+ def get_object(url:)
39
+ ensure_valid_token!
40
+ self.class.base_uri 'https://apis.live.net/v5.0'
41
+ res = self.class.get('/%s' % user_id,
42
+ headers: {
43
+ 'Authorization' => "Bearer #{token}"
44
+ }
45
+ )
46
+ case res.code
47
+ when 200
48
+ JSON.parse(res.body, symbolize_names: true)
49
+ else
50
+ raise ApiError.new res.body
51
+ end
52
+ end
53
+
54
+ def get_collection(url:, limit: 10, offset: 0)
55
+ ensure_valid_token!
56
+ self.class.base_uri 'https://apis.live.net/v5.0'
57
+ res = self.class.get('/%s?limit=%d&offset=%d' % [ url, limit, offset ],
58
+ headers: {
59
+ 'Authorization' => "Bearer #{token}"
60
+ }
61
+ )
62
+ case res.code
63
+ when 200
64
+ JSON.parse(res.body, symbolize_names: true)
65
+ else
66
+ raise ApiError.new res.body
67
+ end
68
+ end
69
+
70
+ def ensure_valid_token!
71
+ if Time.now.to_i > expires_at
72
+ new_auth = renew_token
73
+ self.token = new_auth.token
74
+ self.refresh_token = new_auth.refresh_token
75
+ self.expires_at = new_auth.expires_at
76
+ end
77
+ end
78
+
79
+ def renew_token
80
+ res = self.class.post('/oauth20_token.srf',
81
+ body: {
82
+ client_id: client_id,
83
+ redirect_uri: redirect_uri,
84
+ client_secret: client_secret,
85
+ refresh_token: refresh_token,
86
+ grant_type: :refresh_token
87
+ }
88
+ )
89
+ case res.code
90
+ when 200
91
+ data = JSON.parse(res.body, symbolize_names: true)
92
+ OpenStruct.new(
93
+ token: data[:access_token],
94
+ refresh_token: data[:refresh_token],
95
+ expires_at: Time.now.to_i + data[:expires_in]
96
+ )
97
+ else
98
+ raise RenewTokenError.new res.body
99
+ end
100
+ end
101
+
102
+ end
103
+ end
@@ -0,0 +1 @@
1
+ token_renewer.rb
@@ -0,0 +1,28 @@
1
+
2
+ module MicrosoftLive
3
+ class User
4
+ attr_accessor :id,
5
+ :name,
6
+ :first_name,
7
+ :last_name,
8
+ :gender,
9
+ :link,
10
+ :birth_day,
11
+ :birth_month,
12
+ :birth_year,
13
+ :work, # Object
14
+ :emails, # Object
15
+ :addresses, # Object
16
+ :locale,
17
+ :updated_time,
18
+ :simple
19
+
20
+ def initialize(data: {}, simple:)
21
+ data.each do |key,val|
22
+ self.public_send "#{key}=", val
23
+ end
24
+ self.simple = simple
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,29 @@
1
+
2
+ require 'microsoft-live/simple'
3
+ module MicrosoftLive
4
+ class InvalidConfigError < StandardError; end
5
+ class NotConfiguredError < StandardError; end
6
+ class << self
7
+ attr_accessor :configuration, :did_configure
8
+ @did_configure = false
9
+
10
+ def reset_configuration!
11
+ self.configuration = OpenStruct.new
12
+ self.did_configure = false
13
+ end
14
+
15
+ def configure(&block)
16
+ reset_configuration!
17
+ block.call(self.configuration)
18
+ configuration.client_id or raise InvalidConfigError.new 'config.client_id is required'
19
+ configuration.client_secret or raise InvalidConfigError.new 'config.client_secret is required'
20
+ configuration.redirect_uri or raise InvalidConfigError.new 'config.redirect_uri is required'
21
+ self.did_configure = true
22
+ end
23
+
24
+ def config
25
+ raise InvalidConfigError.new('Configuration not defined') unless self.did_configure
26
+ self.configuration
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = 'microsoft-live-simple'
3
+ spec.version = '0.1.0'
4
+ spec.authors = ['John Drago']
5
+ spec.email = 'jdrago.999@gmail.com'
6
+ spec.homepage = 'https://github.com/jdrago999/microsoft-live-simple'
7
+ spec.summary = 'Client for the Microsoft Live REST API'
8
+ spec.description = 'Client for the Microsoft Live REST API'
9
+ spec.required_rubygems_version = '>= 1.3.6'
10
+
11
+ spec.files = `git ls-files -z`.split("\x0")
12
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
13
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
14
+ spec.require_paths = ['lib']
15
+
16
+ spec.add_development_dependency 'bundler', '~> 1.7'
17
+ spec.add_development_dependency 'rake', '~> 10.0'
18
+ spec.add_development_dependency 'rspec'
19
+ spec.add_development_dependency 'shoulda-matchers'
20
+ spec.add_development_dependency 'byebug'
21
+ spec.add_development_dependency 'simplecov'
22
+ spec.add_development_dependency 'faker'
23
+ spec.add_development_dependency 'webmock'
24
+ spec.add_development_dependency 'rubocop'
25
+
26
+ spec.add_dependency 'httparty'
27
+
28
+ end
29
+
@@ -0,0 +1,97 @@
1
+ require 'spec_helper'
2
+
3
+ describe MicrosoftLive::Collector do
4
+ before :all do
5
+ class Foo
6
+ attr_accessor :data, :simple
7
+ def initialize(data:, simple:)
8
+ self.data = data
9
+ self.simple = simple
10
+ end
11
+ end
12
+ end
13
+ describe 'initialization' do
14
+ before do
15
+ @good_args = {
16
+ simple: double('simple'),
17
+ path: '/x',
18
+ limit: 20,
19
+ offset: 0,
20
+ item_class: 'Object'
21
+ }
22
+ end
23
+ it 'requires :simple' do
24
+ expect{described_class.new(@good_args.except(:simple))}.to raise_error(ArgumentError).with_message('missing keyword: simple')
25
+ end
26
+ it 'requires :path' do
27
+ expect{described_class.new(@good_args.except(:path))}.to raise_error(ArgumentError).with_message('missing keyword: path')
28
+ end
29
+ it 'requires :limit' do
30
+ expect{described_class.new(@good_args.except(:limit))}.to raise_error(ArgumentError).with_message('missing keyword: limit')
31
+ end
32
+ it 'requires :offset' do
33
+ expect{described_class.new(@good_args.except(:offset))}.to raise_error(ArgumentError).with_message('missing keyword: offset')
34
+ end
35
+ it 'requires :item_class' do
36
+ expect{described_class.new(@good_args.except(:item_class))}.to raise_error(ArgumentError).with_message('missing keyword: item_class')
37
+ end
38
+ end
39
+
40
+ describe '#items' do
41
+ before do
42
+ @good_args = {
43
+ simple: double('simple'),
44
+ path: '/x',
45
+ limit: 20,
46
+ offset: 0,
47
+ item_class: Foo
48
+ }
49
+ @collector = described_class.new(@good_args)
50
+ end
51
+ context 'when :data' do
52
+ context 'is empty' do
53
+ before do
54
+ expect(@good_args[:simple]).to receive(:get_collection) do
55
+ { data: [ ] }
56
+ end
57
+ end
58
+ it 'returns an empty array' do
59
+ expect(@collector.items).to eq [ ]
60
+ end
61
+ end
62
+ context 'is not empty' do
63
+ before do
64
+ expect(@good_args[:simple]).to receive(:get_collection) do
65
+ { data: [ 'hello' ] }
66
+ end
67
+ end
68
+ it 'returns an array of :item_class objects' do
69
+ items = @collector.items
70
+ expect(items.first.class).to eq Foo
71
+ expect(items.first.data).to eq 'hello'
72
+ expect(items.first.simple).to eq @good_args[:simple]
73
+ end
74
+ end
75
+ end
76
+ end
77
+
78
+ describe '#next_page' do
79
+ before do
80
+ @good_args = {
81
+ simple: double('simple'),
82
+ path: '/x',
83
+ limit: 20,
84
+ offset: 0,
85
+ item_class: Foo
86
+ }
87
+ @collector = described_class.new(@good_args)
88
+
89
+ expect(@collector).to receive(:offset){ 0 }
90
+ expect(@collector).to receive(:offset=).with(@collector.page_size)
91
+ expect(@collector).to receive(:items)
92
+ end
93
+ it 'increases #offset by #page_size and calls #items' do
94
+ @collector.next_page
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe MicrosoftLive do
4
+ describe '.configure' do
5
+ before do
6
+ @client_id = SecureRandom.uuid
7
+ @client_secret = SecureRandom.uuid
8
+ @redirect_uri = 'https://example.com/%s' % SecureRandom.uuid
9
+ described_class.configure do |config|
10
+ config.client_id = @client_id
11
+ config.client_secret = @client_secret
12
+ config.redirect_uri = @redirect_uri
13
+ end
14
+ end
15
+ it 'sets the client_id' do
16
+ expect(described_class.config.client_id).to eq @client_id
17
+ end
18
+ it 'sets the client_secret' do
19
+ expect(described_class.config.client_secret).to eq @client_secret
20
+ end
21
+ it 'sets the redirect_uri' do
22
+ expect(described_class.config.redirect_uri).to eq @redirect_uri
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe MicrosoftLive::Simple do
4
+ before do
5
+ @client_id = SecureRandom.uuid
6
+ @client_secret = SecureRandom.uuid
7
+ @redirect_uri = 'https://example.com/%s' % SecureRandom.uuid
8
+ MicrosoftLive.configure do |config|
9
+ config.client_id = @client_id
10
+ config.client_secret = @client_secret
11
+ config.redirect_uri = @redirect_uri
12
+ end
13
+
14
+ simple = described_class.new(
15
+ token: 'zzz',
16
+ refresh_token: '123',
17
+ expires_at: (Time.now + 30.seconds).to_i,
18
+ )
19
+ end
20
+ it 'stores the credentials' do
21
+ end
22
+ end
23
+
@@ -0,0 +1,75 @@
1
+ # Did we get executed via 'rake'?
2
+ is_rake_exec = $0 =~ /\/rake/
3
+
4
+ unless is_rake_exec
5
+ ENV['RACK_ENV'] = 'test'
6
+ require 'codeclimate-test-reporter'
7
+ CodeClimate::TestReporter.start
8
+ require 'simplecov'
9
+ SimpleCov.start do
10
+ # add_filter '.vendor/'
11
+ # add_filter 'spec/'
12
+ end
13
+ SimpleCov.minimum_coverage 52
14
+ end
15
+
16
+ require 'rspec'
17
+ require 'bundler'
18
+ require 'shoulda-matchers'
19
+ require 'byebug'
20
+ require 'faker'
21
+ require 'webmock/rspec'
22
+ require 'active_support/all'
23
+
24
+ lib = File.expand_path('../../lib', __FILE__)
25
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
26
+
27
+ require 'microsoft-live'
28
+
29
+ Bundler.load
30
+
31
+ def configure_rspec
32
+
33
+ RSpec.configure do |config|
34
+
35
+ config.expect_with :rspec do |expectations|
36
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
37
+ # Allow foo.should syntax:
38
+ expectations.syntax = [:should, :expect]
39
+ end
40
+
41
+ config.mock_with :rspec do |mocks|
42
+ mocks.syntax = [:should, :expect]
43
+ mocks.verify_partial_doubles = true
44
+ end
45
+
46
+ config.before :suite do
47
+ WebMock.enable!
48
+ WebMock.disable_net_connect!(
49
+ :allow_localhost => false,
50
+ :allow => 'codeclimate.com'
51
+ )
52
+ end
53
+
54
+ config.after :suite do
55
+ WebMock.disable!
56
+ end
57
+
58
+ config.run_all_when_everything_filtered = true
59
+
60
+ config.warnings = true
61
+
62
+ if config.files_to_run.one?
63
+ config.default_formatter = 'doc'
64
+ end
65
+
66
+ config.order = :random
67
+
68
+ Kernel.srand config.seed
69
+ end
70
+ end
71
+
72
+
73
+ unless is_rake_exec
74
+ configure_rspec()
75
+ end
metadata ADDED
@@ -0,0 +1,205 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: microsoft-live-simple
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - John Drago
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-03 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
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
+ - !ruby/object:Gem::Dependency
56
+ name: shoulda-matchers
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
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
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: faker
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: httparty
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: Client for the Microsoft Live REST API
154
+ email: jdrago.999@gmail.com
155
+ executables: []
156
+ extensions: []
157
+ extra_rdoc_files: []
158
+ files:
159
+ - ".gitignore"
160
+ - ".rspec"
161
+ - ".travis.yml"
162
+ - Gemfile
163
+ - Gemfile.lock
164
+ - LICENSE
165
+ - README.md
166
+ - Rakefile
167
+ - lib/microsoft-live.rb
168
+ - lib/microsoft-live/collector.rb
169
+ - lib/microsoft-live/contact.rb
170
+ - lib/microsoft-live/simple.rb
171
+ - lib/microsoft-live/token_renewer.rb
172
+ - lib/microsoft-live/user.rb
173
+ - microsoft-live-simple.gemspec
174
+ - spec/microsoft-live-simple/collector_spec.rb
175
+ - spec/microsoft-live-simple/module_spec.rb
176
+ - spec/microsoft-live-simple/simple_spec.rb
177
+ - spec/spec_helper.rb
178
+ homepage: https://github.com/jdrago999/microsoft-live-simple
179
+ licenses: []
180
+ metadata: {}
181
+ post_install_message:
182
+ rdoc_options: []
183
+ require_paths:
184
+ - lib
185
+ required_ruby_version: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ required_rubygems_version: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: 1.3.6
195
+ requirements: []
196
+ rubyforge_project:
197
+ rubygems_version: 2.2.2
198
+ signing_key:
199
+ specification_version: 4
200
+ summary: Client for the Microsoft Live REST API
201
+ test_files:
202
+ - spec/microsoft-live-simple/collector_spec.rb
203
+ - spec/microsoft-live-simple/module_spec.rb
204
+ - spec/microsoft-live-simple/simple_spec.rb
205
+ - spec/spec_helper.rb