Git Product home page Git Product logo

akamaiopen-edgegrid-ruby's Introduction

edgegrid-ruby

Akamai {OPEN} EdgeGrid Authentication for ruby (net/http)

This library implements the Akamai {OPEN} EdgeGrid Authentication scheme for the ruby net/http library.

For more information visit the Akamai {OPEN} Developer Community.

Installation

This library requires ruby v1.9 or later. To easily install we recommend using rbenv, rubygems and bundler

  • Install from rubygems
gem install akamai-edgegrid
  • Install from sources (we assume you already have rbenv going)
rbenv local 1.9.3-p545
gem install bundler
bundle install
rake test
gem build akamai-edgegrid.gemspec
gem install akamai-edgegrid-1.0.gem

Usage

require 'akamai/edgegrid'
require 'net/http'
require 'uri'

baseuri = URI('https://akaa-xxxxxxxxx.luna.akamaiapis.net/')

http = Akamai::Edgegrid::HTTP.new(
    address=baseuri.host,
    port=baseuri.port
)

http.setup_edgegrid(
    :client_token => 'ccccccccccccccc',
    :client_secret => 'sssssssssssssssssssssss',
    :access_token => 'aaaaaaaaaaaaaaaaaaaa',
    :max_body => 128 * 1024
)

# example of simple GET request
request = Net::HTTP::Get.new URI.join(baseuri.to_s, '/diagnostic-tools/v1/locations').to_s
response = http.request(request)
puts response.body

# exmaple of POST request with a json formatted request body

require 'json'
account_id = 'account-id-goes-here'
start_time = Time.now.to_i * 1000
end_time = start_time + 86400000

post_request = Net::HTTP::Post.new(
    URI.join(baseuri.to_s, "/events/v2/#{account_id}/events").to_s,
    initheader = { 'Content-Type' => 'application/json' }
)

post_request.body = {
    "name" => "A test event",
    "start" => start_time,
    "end" => end_time
}.to_json

post_response = http.request(post_request)
puts post_response.body
  1. First initialize a new EdgegridHTTP object. This is a subclass of Net::HTTP and thus has all methods from that class avaialble for use.

  2. Next initialize the configuration of Edgegrid via the setup_edgegrid method. You must pass the :client_token, and :client_secret from the "Credentials" screen of the Manage APIs UI and the :access_token from the "Authorizations" section of the Manage APIs UI.

  3. Finally, use Net::HTTP methods as usual. EdgegridHTTP will add the property Authentication header to sign your http messages.

Author

Jonathan Landis [email protected]

License

Copyright 2014 Akamai Technologies, Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

akamaiopen-edgegrid-ruby's People

Contributors

bretts avatar jjjhhhlll avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.