learndot_api 0.2.5 → 0.3.0

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
- SHA1:
3
- metadata.gz: fddcda6752cdbc9181405d9e0c38975994d3dfad
4
- data.tar.gz: 4d53953a494753a0e15ed0a48561f85037afcfb7
2
+ SHA256:
3
+ metadata.gz: 06d51d926108dd5346c76fef1cadccbab0a5562148584c9cd0690d70ec3fa74f
4
+ data.tar.gz: f729273b840ecd2fa1203d62e70469ee587db14bc838b9fd3c38eed129ad5c68
5
5
  SHA512:
6
- metadata.gz: 866abb02763938394d832541e2bb9e9d6d01a42f4d74e78d3152f2604607f00f38ff453e2b5bcb54c6891b4bb9ba3afd2d3936b3c3fdbe81abe730d0a76881c5
7
- data.tar.gz: 121d4f7976a0f002237a82204c2af4bb789ffa35d202dffe5d6f37939cade91df231605c46b68b468456dd6a48a9f59da0e50b68bcc4804b1f69c81485688280
6
+ metadata.gz: 93cdc3c103461b105feb8a8a1888123bd8acae73766ef9b320a89076fe8e2f958ee86960c88a8dea6b367ec77251d5dbb30b6c82039facb95a83d4510f5088e4
7
+ data.tar.gz: 27d77286be638ae940333a831abbdaae44733a807a608d99d6ecbdf4e144efbc87f9f0054b773bbcb7c0bba6d71378d0403e55f1e6f92b629dbf44d33d04a7e0
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ v0.3.0
2
+ * Added PoC code for supporting v3 API based on GraphQL
3
+ * Added some common schemas and v3 schema
4
+ * Support for content_component objects
5
+ * Changed token lookup order to use ENV
6
+
1
7
  v0.2.5
2
8
  * Add support for connecting to staging environment
3
9
 
@@ -0,0 +1,187 @@
1
+ {
2
+ "result": {
3
+ "UUID": {
4
+ "type": "string"
5
+ },
6
+ "_displayName_": {
7
+ "type": "string"
8
+ },
9
+ "_keyword_": {
10
+ "type": "string"
11
+ },
12
+ "banner": {
13
+ "type": "string"
14
+ },
15
+ "created": {
16
+ "type": "string"
17
+ },
18
+ "createdById": {
19
+ "type": "number"
20
+ },
21
+ "customField01": {
22
+ "type": "string"
23
+ },
24
+ "customField02": {
25
+ "type": "string"
26
+ },
27
+ "customField03": {
28
+ "type": "string"
29
+ },
30
+ "customField04": {
31
+ "type": "string"
32
+ },
33
+ "customField05": {
34
+ "type": "string"
35
+ },
36
+ "customField06": {
37
+ "type": "string"
38
+ },
39
+ "customField07": {
40
+ "type": "string"
41
+ },
42
+ "customField08": {
43
+ "type": "string"
44
+ },
45
+ "customField09": {
46
+ "type": "string"
47
+ },
48
+ "customField10": {
49
+ "type": "string"
50
+ },
51
+ "deprecatedBy": {
52
+ "type": "string"
53
+ },
54
+ "description": {
55
+ "type": "string"
56
+ },
57
+ "duration": {
58
+ "type": "object",
59
+ "properties": {
60
+ "days": {
61
+ "type": "integer"
62
+ },
63
+ "minutesPerDay": {
64
+ "type": "integer"
65
+ }
66
+ }
67
+ },
68
+ "expiryDays": {
69
+ "type": "integer"
70
+ },
71
+ "fields": {
72
+ "type": "array",
73
+ "items": {
74
+ "type": "any"
75
+ }
76
+ },
77
+ "generateCertificate": {
78
+ "type": "string",
79
+ "enum": [
80
+ "DEFAULT",
81
+ "YES",
82
+ "NO"
83
+ ]
84
+ },
85
+ "generateProofOfCompletion": {
86
+ "type": "string",
87
+ "enum": [
88
+ "DEFAULT",
89
+ "YES",
90
+ "NO"
91
+ ]
92
+ },
93
+ "id": {
94
+ "type": "number"
95
+ },
96
+ "language": {
97
+ "type": "string"
98
+ },
99
+ "logo": {
100
+ "type": "string"
101
+ },
102
+ "modified": {
103
+ "type": "string"
104
+ },
105
+ "modifiedById": {
106
+ "type": "number"
107
+ },
108
+ "name": {
109
+ "type": "string"
110
+ },
111
+ "orderNumber": {
112
+ "type": "integer"
113
+ },
114
+ "price": {
115
+ "type": "object",
116
+ "properties": {
117
+ "amount": {
118
+ "type": "number"
119
+ },
120
+ "currency": {
121
+ "type": "string"
122
+ }
123
+ }
124
+ },
125
+ "primaryCategoryId": {
126
+ "type": "number"
127
+ },
128
+ "providerId": {
129
+ "type": "number"
130
+ },
131
+ "rules": {
132
+ "type": "array",
133
+ "items": {
134
+ "type": "object",
135
+ "properties": {
136
+ "operations": {
137
+ "type": "array",
138
+ "items": {
139
+ "type": "any"
140
+ }
141
+ },
142
+ "restriction": {
143
+ "type": "object",
144
+ "properties": {}
145
+ }
146
+ }
147
+ }
148
+ },
149
+ "salesforceProductId": {
150
+ "type": "string"
151
+ },
152
+ "status": {
153
+ "type": "string",
154
+ "enum": [
155
+ "ENABLED",
156
+ "ACTIVE_COMPONENT",
157
+ "DISABLED"
158
+ ]
159
+ },
160
+ "summary": {
161
+ "type": "string"
162
+ },
163
+ "taxJurisdiction": {
164
+ "type": "string",
165
+ "enum": [
166
+ "EVENT",
167
+ "CUSTOMER",
168
+ "PAYMENT",
169
+ "SHIPPING"
170
+ ]
171
+ },
172
+ "urlName": {
173
+ "type": "string"
174
+ },
175
+ "visibility": {
176
+ "type": "string",
177
+ "enum": [
178
+ "PUBLIC",
179
+ "HIDDEN",
180
+ "MEMBER",
181
+ "DEPRECATED",
182
+ "CUSTOM"
183
+ ]
184
+ }
185
+ },
186
+ "url": "https://learn.puppet.com/api/rest/v2/manage/learning_component/describe"
187
+ }
@@ -0,0 +1,130 @@
1
+ [
2
+ "training_credit_credit_transaction",
3
+ "survey_response",
4
+ "training_survey_response",
5
+ "scheduled_report",
6
+ "page",
7
+ "content_session",
8
+ "stream_post",
9
+ "template",
10
+ "certificate",
11
+ "subscription",
12
+ "elearning_survey_response",
13
+ "agreement",
14
+ "provider",
15
+ "questionnaire_response",
16
+ "tag",
17
+ "survey_response_metric",
18
+ "entity_notification",
19
+ "course_pathway",
20
+ "location_feature",
21
+ "shipping_info",
22
+ "purchase_order_payment",
23
+ "training_opportunity",
24
+ "training_credit_redemption_request",
25
+ "saml_connection",
26
+ "user_group",
27
+ "affiliate_customer_order_conversion",
28
+ "content_option_resource",
29
+ "e_learning_session",
30
+ "course_pathway_type",
31
+ "course",
32
+ "virtual_machine_content",
33
+ "knowledge_category_category",
34
+ "country_state",
35
+ "contact_file_attachment",
36
+ "forum_topic",
37
+ "payment",
38
+ "learning_component_resource",
39
+ "question",
40
+ "credit_card_payment",
41
+ "saml_config",
42
+ "skill",
43
+ "subscription_package",
44
+ "affiliate_visit",
45
+ "learning_pathway_requirement",
46
+ "training_credit_transaction",
47
+ "social_connection",
48
+ "watcher",
49
+ "multiple_choice_question_response",
50
+ "access_right",
51
+ "exam_session",
52
+ "opportunity",
53
+ "timesheet",
54
+ "comment",
55
+ "forum_post",
56
+ "forum_topic_subscription",
57
+ "content",
58
+ "learning_component",
59
+ "training_assessment_response",
60
+ "e_learning_component",
61
+ "course_category",
62
+ "enrolment_resource",
63
+ "public_course_event",
64
+ "course_event",
65
+ "talent_placement",
66
+ "multiple_choice_option",
67
+ "system_setting",
68
+ "staff_role",
69
+ "user_connection",
70
+ "content_option",
71
+ "learning_pathway_session",
72
+ "learning_resource",
73
+ "currency_exchange_rate",
74
+ "affiliate_conversion",
75
+ "discount_use",
76
+ "navigational_link",
77
+ "elearning_testimonial",
78
+ "location",
79
+ "training_credit_payment",
80
+ "forum_subscription",
81
+ "affiliate",
82
+ "link_content",
83
+ "text_question_response",
84
+ "affiliate_payment",
85
+ "agreement_template",
86
+ "questionnaire",
87
+ "learning_session",
88
+ "course_requirement",
89
+ "catalog_group",
90
+ "product_category",
91
+ "text_question",
92
+ "content_component",
93
+ "contact",
94
+ "order_discount",
95
+ "forum",
96
+ "course_event_resource",
97
+ "discount_rule",
98
+ "training_credit_usage",
99
+ "learning_plan",
100
+ "course_pathway_session",
101
+ "proof_of_completion",
102
+ "training_credit_debit_transaction",
103
+ "enrolment",
104
+ "true_ability_content",
105
+ "training_credit_account",
106
+ "badge",
107
+ "order",
108
+ "content_access",
109
+ "trigger",
110
+ "label",
111
+ "knowledge_category",
112
+ "file_attachment",
113
+ "question_response",
114
+ "affiliate_opportunity_conversion",
115
+ "digital_content",
116
+ "course_testimonial",
117
+ "blurb",
118
+ "stream_post_comment",
119
+ "private_course_event",
120
+ "exam_component",
121
+ "product",
122
+ "organization",
123
+ "learning_plan_item",
124
+ "course_session",
125
+ "order_item",
126
+ "testimonial_response",
127
+ "request_for_contact",
128
+ "multiple_choice_question",
129
+ "learning_pathway"
130
+ ]
data/lib/learndot/api.rb CHANGED
@@ -60,9 +60,14 @@ class Learndot::API
60
60
 
61
61
  ############### Private methods ###############
62
62
  def get_token
63
+ return ENV['LEARNDOT_TOKEN'] if ENV.include? 'LEARNDOT_TOKEN'
63
64
  path = File.expand_path('~/.learndot_token')
64
-
65
- File.exists?(path) ? File.read(path).strip : ENV['LEARNDOT_TOKEN']
65
+
66
+ begin
67
+ return File.read(path).strip
68
+ rescue => e
69
+ raise "API token (in env variable or #{path}) not readable. Exiting."
70
+ end
66
71
  end
67
72
 
68
73
  def api_post(endpoint, conditions = {}, query = {})
@@ -0,0 +1,58 @@
1
+ require 'graphql/client'
2
+ require 'graphql/client/http'
3
+ require 'json'
4
+ require 'logger'
5
+
6
+ # Configure GraphQL endpoint using the basic HTTP network adapter.
7
+ HTTP = GraphQL::Client::HTTP.new("https://api.learndot.io/graphql/") do
8
+ def headers(context)
9
+ {
10
+ "X-API-KEY" => ENV['LEARNDOT_TOKEN_V3']
11
+ }
12
+ end
13
+ end
14
+
15
+ # DO NOT regularly get the schema from the API
16
+ # There is a bug on line 10211, part of the PriceInput object; you have to remove the amount's default value.
17
+ # Otherwise, the schema will fail the graphql-client validation
18
+ # GraphQL::Client.dump_schema(HTTP, "schema.json")
19
+
20
+ SCHEMA = GraphQL::Client.load_schema('schema.json')
21
+
22
+ Client = GraphQL::Client.new(
23
+ schema: SCHEMA,
24
+ execute: HTTP
25
+ )
26
+
27
+ # Query = Client.parse <<-'GRAPHQL'
28
+ # {
29
+ # contactByLdeId( ldeId: <int> ) {
30
+ # firstName
31
+ # lastName
32
+ # }
33
+ # }
34
+ # GRAPHQL
35
+
36
+ # Learning Component queries only return ELearning Component types
37
+ # Query = Client.parse <<-'GRAPHQL'
38
+ # {
39
+ # learningComponentByLdeId( ldeId: <int> ) {
40
+ # displayName
41
+ # description
42
+ # }
43
+ # }
44
+ # GRAPHQL
45
+
46
+ Query = Client.parse <<-'GRAPHQL'
47
+ {
48
+ allLearningComponents {
49
+ learningComponents {
50
+ __typename
51
+ }
52
+ }
53
+ }
54
+ GRAPHQL
55
+
56
+ response = Client.query(Query)
57
+
58
+ puts response.data.to_h
@@ -5,31 +5,31 @@ class Learndot::Events
5
5
 
6
6
  def retrieve(conditions, options = {orderBy: 'startTime', asc: true})
7
7
  classes = @api.search(:course_event, conditions, options)
8
-
9
- if !classes.empty?
10
- course_ids = classes.collect { | k, c | c['courseId'] }.uniq
11
- location_ids = classes.collect { | k, c | c['locationId'] }.uniq
12
- organizer_ids = classes.collect { | k, c | c['organizerId'] }.uniq
13
-
14
- courses = @api.search(:course, { 'id' => course_ids })
15
- locations = @api.search(:location, { 'id' => location_ids })
16
- organizers = @api.search(:contact, { 'id' => organizer_ids })
17
-
18
- classes.collect do | class_id, klass |
19
- location = locations[klass['locationId']]
20
-
21
- klass[:learndot_id] = klass['id'] # for consistency
22
- klass[:city] = location['online'] ? location['name'] : location['address']['city']
23
- klass[:course_name] = courses[klass['courseId']]['name']
24
- klass[:organizer] = organizers[klass['organizerId']] ? organizers[klass['organizerId']]['_displayName_'] : ''
25
- klass[:enrollment_count] = enrollment_count(class_id)
26
- klass[:start_time] = Date.parse(klass['startTime'])
27
- klass[:end_time] = Date.parse(klass['finalEndTime'])
28
- klass[:notes] = klass['notes']
29
- klass[:session_url] = klass['sessionUrl']
30
-
31
- klass
32
- end
8
+
9
+ return [] if classes.empty?
10
+
11
+ course_ids = classes.collect { | k, c | c['courseId'] }.uniq
12
+ location_ids = classes.collect { | k, c | c['locationId'] }.uniq
13
+ organizer_ids = classes.collect { | k, c | c['organizerId'] }.uniq
14
+
15
+ courses = @api.search(:course, { 'id' => course_ids })
16
+ locations = @api.search(:location, { 'id' => location_ids })
17
+ organizers = @api.search(:contact, { 'id' => organizer_ids })
18
+
19
+ classes.collect do | class_id, klass |
20
+ location = locations[klass['locationId']]
21
+
22
+ klass[:learndot_id] = klass['id'] # for consistency
23
+ klass[:city] = location['online'] ? location['name'] : location['address']['city']
24
+ klass[:course_name] = courses[klass['courseId']]['name']
25
+ klass[:organizer] = organizers[klass['organizerId']] ? organizers[klass['organizerId']]['_displayName_'] : ''
26
+ klass[:enrollment_count] = enrollment_count(class_id)
27
+ klass[:start_time] = Date.parse(klass['startTime'])
28
+ klass[:end_time] = Date.parse(klass['finalEndTime'])
29
+ klass[:notes] = klass['notes']
30
+ klass[:session_url] = klass['sessionUrl']
31
+
32
+ klass
33
33
  end
34
34
  end
35
35
 
@@ -0,0 +1,23 @@
1
+ class Learndot::LearningComponents
2
+ def initialize(api)
3
+ @api = api
4
+ end
5
+
6
+ def retrieve_component(conditions, options = {orderBy: 'Name', asc: true})
7
+ learning_component = @api.search(:content_component, conditions, options)
8
+ end
9
+
10
+ def create_component(conditions)
11
+ @api.create(:content_component, conditions)
12
+ end
13
+
14
+ def update_component(component_id, conditions={})
15
+ @api.update(:content_component, conditions, component_id)
16
+ end
17
+ end
18
+
19
+ class Learndot
20
+ def learning_component
21
+ Learndot::LearningComponents.new(self.api)
22
+ end
23
+ end