|
1 | 1 | #!/usr/bin/env ruby |
2 | | -# This quickstart guide requires the Ruby codekit, which can be found at: |
| 2 | +# This Quickstart Guide requires the Ruby code kit, |
| 3 | +# which can be found at: |
3 | 4 | # https://github.com/attdevsupport/codekit-ruby |
4 | 5 |
|
5 | | -# Make sure the att-codekit has been installed then require the class |
| 6 | +# Make sure that the att-codekit has been installed, then require the class. |
6 | 7 | require 'att/codekit' |
7 | 8 |
|
8 | | -# Include the name spaces to reduce the code required (Optional) |
| 9 | +# Include the name spaces to reduce the code required (Optional). |
9 | 10 | include Att::Codekit |
10 | 11 |
|
11 | | -# Uncomment to set a proxy if required |
| 12 | +# If a proxy is required, uncomment the following line to set the proxy. |
12 | 13 | # Transport.proxy("http://proxyaddress.com:port") |
13 | 14 |
|
14 | | -# Use the app settings from developer.att.com for the following values. |
15 | | -# Make sure IMMN is enabled for the app key/secret. |
| 15 | +# Use the app account settings from developer.att.com for the following values. |
| 16 | +# Make sure that the API scope is set to MIM before retrieving the App Key and App Secret. |
16 | 17 |
|
17 | | -# Enter the value from 'App Key' field |
| 18 | +# Enter the value from 'App Key' field obtained at developer.att.com |
| 19 | +# in your app account. |
18 | 20 | client_id = 'ENTER VALUE!' |
19 | 21 |
|
20 | | -# Enter the value from 'Secret' field |
| 22 | +# Enter the value from 'App Secret' field obtained at developer.att.com |
| 23 | +# in your app account. |
21 | 24 | client_secret = 'ENTER VALUE!' |
22 | 25 |
|
23 | | -# Set the fqdn to default of https://api.att.com |
| 26 | +# Set the fully-qualified domain name to: https://api.att.com |
24 | 27 | fqdn = 'https://api.att.com' |
25 | 28 |
|
26 | | -# Set the redirect url for returning after consent flow |
| 29 | +# Set the redirect URI for returning after consent flow. |
27 | 30 | base_redirect_url = "http://localhost:4567" |
28 | 31 |
|
29 | | -# Create service for requesting an OAuth token |
| 32 | +# Create the service for requesting an OAuth access token. |
30 | 33 | authcode = Auth::AuthCode.new(fqdn, |
31 | 34 | client_id, |
32 | 35 | client_secret) |
33 | 36 |
|
34 | 37 |
|
35 | | -# Authenticate the user. note: this requires a browser |
| 38 | +# Authenticate the user. Note: This requires a Web browser. |
36 | 39 |
|
37 | | -# Obtain the url string that will be used for consent flow |
| 40 | +# Obtain the url string that is used for consent flow. |
38 | 41 | consent_url = authcode.consentFlow(:redirect => base_redirect_url) |
39 | 42 |
|
40 | | -# display a link with the consent flow url |
| 43 | +# Display the link with the consent flow URI. |
41 | 44 | puts consent_url |
42 | 45 |
|
43 | | -# Wait for user input after spawning consent flow |
| 46 | +# Wait for user input after spawning consent flow. |
44 | 47 | puts "Please input the code in the query parameters after doing consent flow:" |
45 | 48 | code = gets.strip |
46 | 49 |
|
47 | | -# Get the token using the authentication code |
| 50 | +# Get the OAuth access token using the OAuth authentication code. |
48 | 51 | token = authcode.createToken(code) |
49 | 52 |
|
50 | | -# Create a service for making the API call |
| 53 | +# Create a service for making the method request. |
51 | 54 | mim = Service::MIMService.new(fqdn, token) |
52 | 55 |
|
53 | | -# Obtain a list of messages sent to authenticated phone |
| 56 | +# Obtain a list of the messages sent to the authenticated phone. |
54 | 57 | begin |
55 | 58 |
|
56 | 59 | COUNT = 10 |
57 | 60 |
|
58 | 61 | msg_list = mim.getMessageList(COUNT) |
59 | 62 |
|
60 | 63 | rescue Service::ServiceException => e |
61 | | - puts "There was an error, the api returned the following error code:" |
| 64 | + puts "There was an error, the API Gateway returned the following error code:" |
62 | 65 | puts "#{e.message}" |
63 | 66 |
|
64 | 67 | else |
65 | 68 |
|
66 | | - # Simple dump of results |
| 69 | + # Display the results. |
67 | 70 | msg_list.each_pair do |attribute, value| |
68 | 71 | puts "#{attribute}: \t#{value}" |
69 | 72 | end |
|
72 | 75 |
|
73 | 76 | puts |
74 | 77 |
|
75 | | -# Obtain a message by ID |
| 78 | +# Obtain a message by ID. |
76 | 79 | begin |
77 | 80 |
|
78 | | - # Note: this is redundant and only an example; message will contain the same |
| 81 | + # Note: this property also returns the first message in the list and can be used to |
| 82 | + # confirm the return value of the getMessage example that follows. |
79 | 83 | # data as msg_list.messages.first |
80 | 84 |
|
81 | | - # Get the first message from above msg_list |
| 85 | + # Get the first message from the previous msg_list. |
82 | 86 | message = mim.getMessage(msg_list.messages.first.id) |
83 | 87 |
|
84 | 88 | rescue Service::ServiceException => e |
85 | | - puts "There was an error, the api returned the following error code:" |
| 89 | + puts "There was an error, the API Gateway returned the following error code:" |
86 | 90 | puts "#{e.message}" |
87 | 91 |
|
88 | 92 | else |
89 | 93 |
|
90 | | - # Simple dump of results |
| 94 | + # Display the results. |
91 | 95 | message.each_pair do |attribute, value| |
92 | 96 | puts "#{attribute}: \t#{value}" |
93 | 97 | end |
|
96 | 100 |
|
97 | 101 | puts |
98 | 102 |
|
99 | | -# Obtain content of an mms message |
| 103 | +# Obtain the content of an MMS message. |
100 | 104 | begin |
101 | 105 |
|
102 | | - # Note: you will only be able to obtain the content of an mms message |
| 106 | + # Note: You will be able to only obtain the content of an MMS message. |
103 | 107 |
|
104 | 108 | content = mim.getMessageContent(msg_list.messages.first.id) |
105 | 109 |
|
106 | 110 | rescue Service::ServiceException => e |
107 | | - puts "There was an error, the api returned the following error code:" |
| 111 | + puts "There was an error, the API Gateway returned the following error code:" |
108 | 112 | puts "#{e.message}" |
109 | 113 |
|
110 | 114 | else |
111 | 115 |
|
112 | | - # Simple dump of results |
| 116 | + # Display the results. |
113 | 117 | puts "Content type: #{content.content_type}" |
114 | 118 | puts "Content length: #{content.content_length}" |
115 | 119 | puts "Image? #{content.image?}" |
|
0 commit comments