GithubHelp home page GithubHelp logo

fastly-ruby's Introduction

Fastly Build Status

Client library for interacting with the Fastly web acceleration service API

Example

# Gemfile
gem 'fastly'

# some_file.rb
fastly = Fastly.new(login_opts)

current_user     = fastly.current_user
current_customer = fastly.current_customer

user     = fastly.get_user(current_user.id)
customer = fastly.get_customer(current_customer.id)

puts "Name: #{user.name}"
puts "Works for #{user.customer.name}"
puts "Which is the same as #{customer.name}"
puts "Which has the owner #{customer.owner.name}"

# Let's see which services we have defined
fastly.list_services.each do |service|
  puts "Service ID: #{service.id}"
  puts "Service Name: #{service.name}"
  puts "Service Versions:"
  service.versions.each do |version|
    puts "\t#{version.number}"
  end
end

service        = fastly.create_service(:name => "MyFirstService")
latest_version = service.version

# Create a domain and a backend for the service ...
domain         = fastly.create_domain(:service_id => service.id, :version => latest_version.number, :name => "www.example.com")
backend        = fastly.create_backend(:service_id => service.id, :version => latest_version.number, :name => "Backend 1", :ipv4 => "192.0.43.10", :port => 80)

# ... and activate it. You're now hosted on Fastly.
latest_version.activate!

# Let's take a peek at the VCL that Fastly generated for us
vcl = latest_version.generated_vcl
puts "Generated VCL file is:\n#{vcl.content}"

# Now let's create a new version ...
new_version    = latest_version.clone
# ... add a new backend ...
new_backend    = fastly.create_backend(:service_id => service.id, :version => new_version.number, :name => "Backend 2", :ipv4 => "74.125.224.136", :port => 8080)
# ... add a director to switch between them
director       = fastly.create_director(:service_id => service.id, :version => new_version.number, :name => "My Director")
director.add_backend(backend)
director.add_backend(new_backend)
# ... and upload some custom vcl (presuming we have permissions)
new_version.upload_vcl(vcl_name, File.read(vcl_file))
# ... and set it as the service's main vcl
new_version.vcl(vcl_name).set_main!

new_version.activate!

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Notes for testing

The test suite requires the following ENV variables to be set:

  • FASTLY_TEST_USER - Your user email
  • FASTLY_TEST_PASSWORD - Your account password
  • FASTLY_TEST_API_KEY - Your API key (found at https://app.fastly.com/#account)

While the test suite is safe to be run on all accounts and isn't harmful to your data, the tests will create and delete 3 services in sequence so you may want to create an account just for tests.

Copyright

Copyright 2011-2014 - Fastly Inc

Redistribution

MIT license, see LICENSE.

Contact

Mail support at fastly dot com if you have problems.

Developers

fastly-ruby's People

Contributors

aspires avatar athomason avatar ctdk avatar ezkl avatar jkthorne avatar kzk avatar mmay avatar phlipper avatar renholm avatar rsandor avatar ryanatwork avatar sgerrand avatar simonwistow avatar sivy avatar spra85 avatar thommahoney avatar tyler 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.