microsoft_graph 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +11 -11
  3. data/.rspec +2 -2
  4. data/.travis.yml +4 -4
  5. data/Gemfile +4 -4
  6. data/LICENSE +10 -10
  7. data/README.md +99 -98
  8. data/Rakefile +7 -7
  9. data/data/metadata_v1.0.xml +1686 -1686
  10. data/integration_spec/integration_spec_helper.rb +18 -18
  11. data/integration_spec/live_spec.rb +180 -180
  12. data/lib/microsoft_graph.rb +35 -35
  13. data/lib/microsoft_graph/base.rb +110 -110
  14. data/lib/microsoft_graph/base_entity.rb +152 -152
  15. data/lib/microsoft_graph/cached_metadata_directory.rb +3 -3
  16. data/lib/microsoft_graph/class_builder.rb +217 -217
  17. data/lib/microsoft_graph/collection.rb +95 -95
  18. data/lib/microsoft_graph/collection_association.rb +232 -232
  19. data/lib/microsoft_graph/errors.rb +6 -6
  20. data/lib/microsoft_graph/version.rb +3 -3
  21. data/lib/odata.rb +49 -49
  22. data/lib/odata/entity_set.rb +20 -20
  23. data/lib/odata/errors.rb +18 -18
  24. data/lib/odata/navigation_property.rb +30 -30
  25. data/lib/odata/operation.rb +17 -17
  26. data/lib/odata/property.rb +38 -38
  27. data/lib/odata/request.rb +49 -49
  28. data/lib/odata/service.rb +279 -279
  29. data/lib/odata/singleton.rb +20 -20
  30. data/lib/odata/type.rb +25 -25
  31. data/lib/odata/types/collection_type.rb +30 -30
  32. data/lib/odata/types/complex_type.rb +19 -19
  33. data/lib/odata/types/entity_type.rb +33 -33
  34. data/lib/odata/types/enum_type.rb +37 -37
  35. data/lib/odata/types/primitive_type.rb +12 -12
  36. data/lib/odata/types/primitive_types/binary_type.rb +15 -15
  37. data/lib/odata/types/primitive_types/boolean_type.rb +15 -15
  38. data/lib/odata/types/primitive_types/date_time_offset_type.rb +15 -15
  39. data/lib/odata/types/primitive_types/date_type.rb +23 -23
  40. data/lib/odata/types/primitive_types/double_type.rb +16 -16
  41. data/lib/odata/types/primitive_types/guid_type.rb +24 -24
  42. data/lib/odata/types/primitive_types/int_16_type.rb +19 -19
  43. data/lib/odata/types/primitive_types/int_32_type.rb +15 -15
  44. data/lib/odata/types/primitive_types/int_64_type.rb +15 -15
  45. data/lib/odata/types/primitive_types/stream_type.rb +15 -15
  46. data/lib/odata/types/primitive_types/string_type.rb +15 -15
  47. data/microsoft_graph-0.1.2.gem +0 -0
  48. data/microsoft_graph.gemspec +31 -31
  49. data/tasks/update_metadata.rb +17 -17
  50. metadata +6 -6
  51. data/microsoft_graph-0.1.0.gem +0 -0
@@ -1,18 +1,18 @@
1
- require "common_spec_helper"
2
- require "dotenv"
3
- Dotenv.load
4
- # ADAL::Logging.log_level = ADAL::Logger::VERBOSE
5
-
6
- TENANT = ENV['MS_GRAPH_TENANT']
7
- USERNAME = ENV['MS_GRAPH_USERNAME']
8
- PASSWORD = ENV['MS_GRAPH_PASSWORD']
9
- CLIENT_ID = ENV['MS_GRAPH_CLIENT_ID']
10
- CLIENT_SECRET = ENV['MS_GRAPH_CLIENT_SECRET']
11
- RESOURCE = 'https://graph.microsoft.com'
12
-
13
- USER_CRED = ADAL::UserCredential.new(USERNAME, PASSWORD)
14
- CLIENT_CRED = ADAL::ClientCredential.new(CLIENT_ID, CLIENT_SECRET)
15
- CONTEXT = ADAL::AuthenticationContext.new(ADAL::Authority::WORLD_WIDE_AUTHORITY, TENANT)
16
- TOKENS = CONTEXT.acquire_token_for_user(RESOURCE, CLIENT_CRED, USER_CRED)
17
-
18
- create_classes(TOKENS)
1
+ require "common_spec_helper"
2
+ require "dotenv"
3
+ Dotenv.load
4
+ # ADAL::Logging.log_level = ADAL::Logger::VERBOSE
5
+
6
+ TENANT = ENV['MS_GRAPH_TENANT']
7
+ USERNAME = ENV['MS_GRAPH_USERNAME']
8
+ PASSWORD = ENV['MS_GRAPH_PASSWORD']
9
+ CLIENT_ID = ENV['MS_GRAPH_CLIENT_ID']
10
+ CLIENT_SECRET = ENV['MS_GRAPH_CLIENT_SECRET']
11
+ RESOURCE = 'https://graph.microsoft.com'
12
+
13
+ USER_CRED = ADAL::UserCredential.new(USERNAME, PASSWORD)
14
+ CLIENT_CRED = ADAL::ClientCredential.new(CLIENT_ID, CLIENT_SECRET)
15
+ CONTEXT = ADAL::AuthenticationContext.new(ADAL::Authority::WORLD_WIDE_AUTHORITY, TENANT)
16
+ TOKENS = CONTEXT.acquire_token_for_user(RESOURCE, CLIENT_CRED, USER_CRED)
17
+
18
+ create_classes(TOKENS)
@@ -1,180 +1,180 @@
1
- require_relative "integration_spec_helper"
2
-
3
- describe MicrosoftGraph::User do
4
- Given(:auth_callback) {
5
- Proc.new { |r| r.headers["Authorization"] = "Bearer #{TOKENS.access_token}" }
6
- }
7
- Given(:test_run_id) { rand(2**128) }
8
- Given(:graph) { MicrosoftGraph.new(&auth_callback) }
9
- Given(:user) { graph.users.take(3).last }
10
- Given(:email_destination) { user.user_principal_name }
11
- Given(:message_template) {
12
- {
13
- subject: "test message #{test_run_id}",
14
- body: {
15
- content: "Hello.\n\nThis message is generated by an automated test suite.",
16
- },
17
- to_recipients: [
18
- { email_address: { address: email_destination } },
19
- ],
20
- }
21
- }
22
-
23
- describe 'current user' do
24
- Given(:subject) { graph.me }
25
-
26
- describe 'direct reports' do
27
- When(:result) { subject.direct_reports.take(5) }
28
- Then { result.length == 0 }
29
- end
30
-
31
- describe 'membership' do
32
- Given(:groups) { subject.member_of.take(5) }
33
- Given(:group) { groups.last }
34
-
35
- When(:result) { subject.check_member_groups(group_ids: [group.id]) }
36
-
37
- Then { result.to_a == [group.id] }
38
- And { groups.length == 5 }
39
- And { group.display_name.length > 0 }
40
- end
41
-
42
- describe MicrosoftGraph::Drive do
43
- Given(:drive) { subject.drive }
44
-
45
- describe MicrosoftGraph::DriveItem do
46
- Given(:root) { drive.root }
47
- Given(:root_contents) { root.children }
48
-
49
- Then { root_contents.size == 0 }
50
- end
51
- end
52
-
53
- describe 'contacts' do
54
- Given(:contacts) { subject.contacts.take(5) }
55
- Given(:contact) { contacts.last }
56
-
57
- Then { contacts.to_a.size == 5 }
58
- And { contact.display_name.length > 0 }
59
- end
60
-
61
- describe 'email' do
62
- describe 'send a new email' do
63
- When(:result) { subject.send_mail(message: message_template) }
64
- Then { result != Failure() }
65
- end
66
- end
67
-
68
- describe 'messages' do
69
- Given(:messages) { subject.mail_folders.find('Inbox').messages }
70
- Given(:first_five_messages) { messages.take(5) }
71
- Given(:message) { first_five_messages.last }
72
-
73
- describe 'list' do
74
- When(:result) { first_five_messages.size }
75
- Then { result == 5 }
76
- end
77
-
78
- describe 'post a reply' do
79
- When(:result) { message.create_reply('test reply') }
80
- Then { result != Failure() }
81
- end
82
-
83
- describe 'post a reply-all' do
84
- When(:result) { message.create_reply_all('test reply-all') }
85
- Then { result != Failure() }
86
- end
87
-
88
- describe 'drafts' do
89
- Given(:draft_messages) { subject.mail_folders.find('Drafts').messages }
90
- # Note: Graph API seems to not allow you to find a mail_folder with a space in its name like we do above
91
- Given(:sent_messages) { subject.mail_folders.detect { |f| f.display_name == 'Sent Items' }.messages }
92
-
93
- describe 'post and send a draft message' do
94
- When(:draft_message) { draft_messages.create!(message_template) }
95
- When(:draft_id) { draft_message.id }
96
- When(:draft_title) { draft_message.subject }
97
- When(:send_result) { draft_message.send }
98
- When { sleep 0.5 }
99
- When(:try_finding_in_drafts) { draft_messages.find(draft_id) }
100
- # below could find the wrong message if someone else is sending at the same time:
101
- When(:sent_message) { sent_messages.order_by('sentDateTime desc').first }
102
- When(:sent_title) { sent_message.subject }
103
-
104
- Then { send_result != Failure() }
105
- And { try_finding_in_drafts == Failure(OData::ClientError, /404/) }
106
- And { sent_title == draft_title }
107
- end
108
- end
109
- end
110
-
111
- describe 'calendar' do
112
- Given(:calendar) { subject.calendar }
113
- Given(:event_template) {
114
- {
115
- subject: 'test event',
116
- body: {
117
- content: 'this event generated by an automated test suite'
118
- },
119
- }
120
- }
121
-
122
- describe 'events' do
123
- Given(:events) { calendar.events }
124
-
125
- describe 'new' do
126
-
127
- describe 'create!' do
128
- When(:event) { events.create!(event_template) }
129
- When(:id) { event.id }
130
- When(:title) { event.subject }
131
- When { event.delete! }
132
- When(:get_deleted_event) { events.find(id) }
133
-
134
- Then { title == event_template[:subject] }
135
- And { get_deleted_event == Failure(OData::ClientError, /404/) }
136
- end
137
-
138
- describe 'create recurring' do
139
- Given(:start_date) { Date.today }
140
- Given(:recurring_event_template) {
141
- event_template.merge(
142
- recurrence: {
143
- pattern: {
144
- days_of_week: [start_date.strftime('%A').downcase],
145
- interval: 1,
146
- type: 'weekly',
147
- },
148
- range: {
149
- start_date: start_date,
150
- type: 'noEnd',
151
- },
152
- }
153
- )
154
- }
155
- When(:event) { events.create!(recurring_event_template) }
156
- When(:id) { event.id }
157
- When(:title) { event.subject }
158
- When { event.delete! }
159
- When(:get_deleted_event) { events.find(id) }
160
-
161
- Then { id.length > 0 }
162
- And { title == event_template[:subject] }
163
- And { get_deleted_event == Failure(OData::ClientError, /404/) }
164
- end
165
-
166
- describe 'add attachment'
167
- end
168
-
169
- describe 'existing' do
170
- describe 'first invitation' do
171
- describe 'tentatively accept'
172
- describe 'accept'
173
- describe 'decline'
174
- end
175
- end
176
- end
177
- end
178
- end
179
-
180
- end
1
+ require_relative "integration_spec_helper"
2
+
3
+ describe MicrosoftGraph::User do
4
+ Given(:auth_callback) {
5
+ Proc.new { |r| r.headers["Authorization"] = "Bearer #{TOKENS.access_token}" }
6
+ }
7
+ Given(:test_run_id) { rand(2**128) }
8
+ Given(:graph) { MicrosoftGraph.new(&auth_callback) }
9
+ Given(:user) { graph.users.take(3).last }
10
+ Given(:email_destination) { user.user_principal_name }
11
+ Given(:message_template) {
12
+ {
13
+ subject: "test message #{test_run_id}",
14
+ body: {
15
+ content: "Hello.\n\nThis message is generated by an automated test suite.",
16
+ },
17
+ to_recipients: [
18
+ { email_address: { address: email_destination } },
19
+ ],
20
+ }
21
+ }
22
+
23
+ describe 'current user' do
24
+ Given(:subject) { graph.me }
25
+
26
+ describe 'direct reports' do
27
+ When(:result) { subject.direct_reports.take(5) }
28
+ Then { result.length == 0 }
29
+ end
30
+
31
+ describe 'membership' do
32
+ Given(:groups) { subject.member_of.take(5) }
33
+ Given(:group) { groups.last }
34
+
35
+ When(:result) { subject.check_member_groups(group_ids: [group.id]) }
36
+
37
+ Then { result.to_a == [group.id] }
38
+ And { groups.length == 5 }
39
+ And { group.display_name.length > 0 }
40
+ end
41
+
42
+ describe MicrosoftGraph::Drive do
43
+ Given(:drive) { subject.drive }
44
+
45
+ describe MicrosoftGraph::DriveItem do
46
+ Given(:root) { drive.root }
47
+ Given(:root_contents) { root.children }
48
+
49
+ Then { root_contents.size == 0 }
50
+ end
51
+ end
52
+
53
+ describe 'contacts' do
54
+ Given(:contacts) { subject.contacts.take(5) }
55
+ Given(:contact) { contacts.last }
56
+
57
+ Then { contacts.to_a.size == 5 }
58
+ And { contact.display_name.length > 0 }
59
+ end
60
+
61
+ describe 'email' do
62
+ describe 'send a new email' do
63
+ When(:result) { subject.send_mail(message: message_template) }
64
+ Then { result != Failure() }
65
+ end
66
+ end
67
+
68
+ describe 'messages' do
69
+ Given(:messages) { subject.mail_folders.find('Inbox').messages }
70
+ Given(:first_five_messages) { messages.take(5) }
71
+ Given(:message) { first_five_messages.last }
72
+
73
+ describe 'list' do
74
+ When(:result) { first_five_messages.size }
75
+ Then { result == 5 }
76
+ end
77
+
78
+ describe 'post a reply' do
79
+ When(:result) { message.create_reply('test reply') }
80
+ Then { result != Failure() }
81
+ end
82
+
83
+ describe 'post a reply-all' do
84
+ When(:result) { message.create_reply_all('test reply-all') }
85
+ Then { result != Failure() }
86
+ end
87
+
88
+ describe 'drafts' do
89
+ Given(:draft_messages) { subject.mail_folders.find('Drafts').messages }
90
+ # Note: Graph API seems to not allow you to find a mail_folder with a space in its name like we do above
91
+ Given(:sent_messages) { subject.mail_folders.detect { |f| f.display_name == 'Sent Items' }.messages }
92
+
93
+ describe 'post and send a draft message' do
94
+ When(:draft_message) { draft_messages.create!(message_template) }
95
+ When(:draft_id) { draft_message.id }
96
+ When(:draft_title) { draft_message.subject }
97
+ When(:send_result) { draft_message.send }
98
+ When { sleep 0.5 }
99
+ When(:try_finding_in_drafts) { draft_messages.find(draft_id) }
100
+ # below could find the wrong message if someone else is sending at the same time:
101
+ When(:sent_message) { sent_messages.order_by('sentDateTime desc').first }
102
+ When(:sent_title) { sent_message.subject }
103
+
104
+ Then { send_result != Failure() }
105
+ And { try_finding_in_drafts == Failure(OData::ClientError, /404/) }
106
+ And { sent_title == draft_title }
107
+ end
108
+ end
109
+ end
110
+
111
+ describe 'calendar' do
112
+ Given(:calendar) { subject.calendar }
113
+ Given(:event_template) {
114
+ {
115
+ subject: 'test event',
116
+ body: {
117
+ content: 'this event generated by an automated test suite'
118
+ },
119
+ }
120
+ }
121
+
122
+ describe 'events' do
123
+ Given(:events) { calendar.events }
124
+
125
+ describe 'new' do
126
+
127
+ describe 'create!' do
128
+ When(:event) { events.create!(event_template) }
129
+ When(:id) { event.id }
130
+ When(:title) { event.subject }
131
+ When { event.delete! }
132
+ When(:get_deleted_event) { events.find(id) }
133
+
134
+ Then { title == event_template[:subject] }
135
+ And { get_deleted_event == Failure(OData::ClientError, /404/) }
136
+ end
137
+
138
+ describe 'create recurring' do
139
+ Given(:start_date) { Date.today }
140
+ Given(:recurring_event_template) {
141
+ event_template.merge(
142
+ recurrence: {
143
+ pattern: {
144
+ days_of_week: [start_date.strftime('%A').downcase],
145
+ interval: 1,
146
+ type: 'weekly',
147
+ },
148
+ range: {
149
+ start_date: start_date,
150
+ type: 'noEnd',
151
+ },
152
+ }
153
+ )
154
+ }
155
+ When(:event) { events.create!(recurring_event_template) }
156
+ When(:id) { event.id }
157
+ When(:title) { event.subject }
158
+ When { event.delete! }
159
+ When(:get_deleted_event) { events.find(id) }
160
+
161
+ Then { id.length > 0 }
162
+ And { title == event_template[:subject] }
163
+ And { get_deleted_event == Failure(OData::ClientError, /404/) }
164
+ end
165
+
166
+ describe 'add attachment'
167
+ end
168
+
169
+ describe 'existing' do
170
+ describe 'first invitation' do
171
+ describe 'tentatively accept'
172
+ describe 'accept'
173
+ describe 'decline'
174
+ end
175
+ end
176
+ end
177
+ end
178
+ end
179
+
180
+ end
@@ -1,35 +1,35 @@
1
- require "odata"
2
-
3
- Dir[
4
- File.join(
5
- File.dirname(__FILE__),
6
- 'microsoft_graph',
7
- '*'
8
- )
9
- ].sort.each { |f| require f }
10
-
11
- class MicrosoftGraph
12
- attr_reader :service
13
- BASE_URL = "https://graph.microsoft.com/v1.0/"
14
-
15
- def initialize(options = {}, &auth_callback)
16
- @service = OData::Service.new(
17
- base_url: BASE_URL,
18
- metadata_file: options[:cached_metadata_file],
19
- auth_callback: auth_callback
20
- )
21
- @association_collections = {}
22
- unless MicrosoftGraph::ClassBuilder.loaded?
23
- MicrosoftGraph::ClassBuilder.load!(service)
24
- end
25
-
26
- end
27
-
28
- def containing_navigation_property(type_name)
29
- navigation_properties.values.find do |navigation_property|
30
- navigation_property.collection? && navigation_property.type.name == "Collection(#{type_name})"
31
- end
32
- end
33
-
34
- def path; end
35
- end
1
+ require "odata"
2
+
3
+ Dir[
4
+ File.join(
5
+ File.dirname(__FILE__),
6
+ 'microsoft_graph',
7
+ '*'
8
+ )
9
+ ].sort.each { |f| require f }
10
+
11
+ class MicrosoftGraph
12
+ attr_reader :service
13
+ BASE_URL = "https://graph.microsoft.com/v1.0/"
14
+
15
+ def initialize(options = {}, &auth_callback)
16
+ @service = OData::Service.new(
17
+ base_url: BASE_URL,
18
+ metadata_file: options[:cached_metadata_file],
19
+ auth_callback: auth_callback
20
+ )
21
+ @association_collections = {}
22
+ unless MicrosoftGraph::ClassBuilder.loaded?
23
+ MicrosoftGraph::ClassBuilder.load!(service)
24
+ end
25
+
26
+ end
27
+
28
+ def containing_navigation_property(type_name)
29
+ navigation_properties.values.find do |navigation_property|
30
+ navigation_property.collection? && navigation_property.type.name == "Collection(#{type_name})"
31
+ end
32
+ end
33
+
34
+ def path; end
35
+ end