Skip to content

Commit 522fa9b

Browse files
author
attdevsupport
committed
Release 3.1 CR/fixes
1 parent d1d4462 commit 522fa9b

427 files changed

Lines changed: 30969 additions & 8468 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

RESTFul/ADS/Ruby/app1/README

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
*******************************************************************************
2+
* Licensed by AT&T under 'Software Development Kit Tools Agreement.'
3+
*
4+
* 2013 TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION:
5+
* http://developer.att.com/sdk_agreement/
6+
*
7+
* Copyright 2013 AT&T Intellectual Property. All rights reserved.
8+
* http://developer.att.com
9+
*
10+
* For more information contact developer.support@att.com
11+
*******************************************************************************
12+
13+
AT&T API Platform Sample Apps
14+
--------------------------------------
15+
16+
This file describes how to set up, configure and run the Ruby sample
17+
applications using the AT&T API Platform services. It covers all steps
18+
required to register the applications on DevConnect as well as running the
19+
sample applications locally.
20+
21+
1. Configuration
22+
2. Installation
23+
3. Parameters
24+
4. Running the application
25+
26+
27+
1. Configuration
28+
29+
Configuration consists of a few steps necessary to get an application
30+
registered on DevConnect with the proper services and endpoints, depending on
31+
the type of client-side application (autonomous/non-autonomous).
32+
33+
To register an application, go to https://devconnect-api.att.com/ and login
34+
with your valid username and password. Next, choose "My Apps" from the bar at
35+
the top of the page and click the "Setup a New Application" button.
36+
37+
Fill in the form, in particular all fields marked as "required".
38+
39+
Be careful while filling in the "OAuth Redirect URL" field. It should contain
40+
the URL that the OAuth provider will redirect users to when he/she
41+
successfully authenticates and authorizes your application. The oauth
42+
redirect field must match the redirect specified in the app's config.yml
43+
44+
NOTE: You MUST select the Sample Applications name in the list of services
45+
under field 'Services' in order to enable access to the cloud api.
46+
47+
After your application is registered you will receive an API and Secret key.
48+
They are necessary for your registered applications to access the AT&T
49+
Platform APIs. See 'Adjusting parameters' below to learn how to use these
50+
keys in your applications.
51+
52+
Initially your newly registered application is restricted to the "Sandbox"
53+
environment only. To move it to production, you may promote it by clicking
54+
the "Promote to production" button. Notice that you will get a different API
55+
key and secret, so these values in your application should be adjusted
56+
accordingly.
57+
58+
Depending on the kind of authentication used, an application may be based on
59+
either the Autonomous Client or the Web-Server Client OAuth flow; see:
60+
https://devconnect-api.att.com/docs/oauth20/autonomous-client-application-oauth-flow
61+
https://devconnect-api.att.com/docs/oauth20/web-server-client-application-oauth-flow
62+
63+
64+
2. Installation
65+
66+
** Requirements
67+
68+
To run the examples you will need ruby 1.8+ and a few ruby gems that the
69+
applications are built upon:
70+
71+
- sinatra: (http://www.sinatrarb.com/) used to construct a simple web
72+
application and manage URLs within.
73+
74+
- sinatra-contrib: additional set of useful helpers, including ones used to
75+
read settings from external files.
76+
77+
- rest-client: library for making restful calls
78+
79+
- json: used for encoding and decoding requests/responses
80+
81+
- att-codekit: library developed around the att cloud services (see below
82+
to install)
83+
- rake: compiling tool used to make att-codekit
84+
- yard: documentation tool used by att-codekit
85+
86+
To install these gems open up a terminal window and invoke:
87+
88+
gem install sinatra sinatra-contrib rest-client json rake yard
89+
90+
On a *nix based system you may need to raise your access privliges, such as
91+
prefixing the command with sudo or logging in as root by running su.
92+
93+
** Installing the att-codekit library
94+
Note: required for ruby 1.9+ and suggested for 1.8
95+
96+
The code kit library can be installed by using our hosted gem file.
97+
98+
gem sources --add http://ldev.code-apt-att.com:8808
99+
gem install att-codekit
100+
101+
Note that the codekit is under heavy development and is using a semantic
102+
versioning scheme. Non-backwards compatible changes _will_ increase the
103+
major version number.
104+
105+
106+
** Setting up on a different port number
107+
108+
In the case multiple applications need to be run at the same time, you need
109+
to use different port numbers.
110+
111+
By default sinatra uses port number 4567; however only one running
112+
application may use this port. In the case that you want to run more than one
113+
sinatra-based application, you will need to update each applications' port
114+
number (located in config.yml).
115+
116+
eg. application 1 - port: 4567, application 2 - port: 4568
117+
118+
The alternative is to set up your webserver to use a tool such as phusion
119+
passenger. Setting up a webserver, however, is beyond the scope of this
120+
article.
121+
122+
123+
3. Parameters
124+
125+
Each application contains a config.yml file. It holds configurable parameters
126+
described in the easy to read format YAML. You are free to adjust these to
127+
your needs. If you introduce a change make sure to restart the application
128+
for it to take effect.
129+
130+
The following are short descriptions of commonly used parameters:
131+
132+
REQUIRED -
133+
1) FQDN : The main server handling requests, ex: https://api.att.com
134+
135+
2) api_key : set the value as per your registered application 'API
136+
key' field value
137+
138+
3) secret_key : set the value as per your registered application
139+
'Secret key' field value
140+
141+
OPTIONAL -
142+
4) port : The port number which the application will run standalone
143+
144+
5) tokens_file : The path where the oauth token will be saved. This option
145+
is only usable in client credential style authentication.
146+
Must have write permissions.
147+
148+
Note: If your application is promoted from the Sandbox environment to
149+
Production environment and you decide to use production application settings,
150+
you must update api_key and secret_key as per production application details.
151+
152+
153+
4. Running the application
154+
155+
To run the application, open up a terminal window in the application's
156+
directory and type:
157+
158+
ruby (app name).rb
159+
160+
Where (app name) is replaced with the current directories app name.
161+
162+
Your application by default is accessible in a web browser at the url:
163+
http://localhost:4567/
164+
165+
You may interrupt the application at any time by pressing ctrl-C.
166+
167+

RESTFul/ADS/Ruby/app1/README.txt

Lines changed: 0 additions & 124 deletions
This file was deleted.

RESTFul/ADS/Ruby/app1/ads.rb

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
require 'sinatra'
1212
require 'open-uri'
1313
require 'sinatra/config_file'
14-
require 'att_oauth_service'
14+
require 'att/codekit'
15+
16+
#simplify our namespace
17+
include Att::Codekit
1518

1619
enable :sessions
1720

@@ -25,12 +28,14 @@
2528

2629
configure do
2730
begin
28-
OAuth = AttCloudServices::OAuthService.new(settings.FQDN,
29-
settings.api_key,
30-
settings.secret_key,
31-
SCOPE,
32-
:tokens_file => settings.tokens_file)
33-
rescue => e
31+
VALID_PARAMS = [:Category, :MMA]
32+
oauth = Auth::ClientCred.new(settings.FQDN,
33+
settings.api_key,
34+
settings.secret_key,
35+
SCOPE,
36+
:tokens_file => settings.tokens_file)
37+
Ads = Service::ADService.new(oauth)
38+
rescue Exception => e
3439
@error = e.message
3540
end
3641
end
@@ -40,35 +45,35 @@
4045
end
4146

4247
post '/getAds' do
43-
get_ads
44-
end
48+
begin
49+
args = Hash.new
4550

46-
def get_ads
47-
invalidParams = Array.new
51+
VALID_PARAMS.each do |p|
52+
args[p] = params[p].strip unless params[p].nil? or params[p].strip.empty?
53+
end
4854

49-
if params[:category]
50-
url = "#{settings.FQDN}/rest/1/ads?Category=#{params[:category]}"
51-
else
52-
invalidParams << "Category"
53-
end
55+
heads = {
56+
:User_Agent => @env["HTTP_USER_AGENT"].to_s,
57+
:UDID => "012266005922565000000000000000"
58+
}
5459

55-
if invalidParams.any?
56-
@error = "Invalid parameters: " + invalidParams.join(", ")
57-
else
58-
response = RestClient.get(url, :Authorization => "BEARER #{OAuth.access_token}", :User_Agent => "#{@env["HTTP_USER_AGENT"]}", :UDID => "012266005922565000000000000000", :Content_Type => 'application/json', :Accept => 'application/json')
59-
60-
case response.code
61-
when 204
62-
@no_ads = 'No Ads were returned'
63-
when 200,201
64-
@result = JSON.parse(response)["AdsResponse"]["Ads"]
65-
else
66-
@error = response
67-
end
68-
end
60+
response = Ads.get_ads(args, heads)
6961

70-
rescue => e
71-
@error = e.message
72-
ensure
73-
return erb :ads
62+
case response.code
63+
when 204
64+
@no_ads = 'No Ads were returned'
65+
when 200,201
66+
puts response
67+
@result = JSON.parse(response)["AdsResponse"]["Ads"]
68+
else
69+
@error = response
70+
end
71+
72+
rescue RestClient::Exception => e
73+
@error = e.response
74+
rescue Exception => e
75+
@error = e.message
76+
end
77+
erb :ads
7478
end
79+

0 commit comments

Comments
 (0)