Sha256: c3a42022bed6bab8375640c47e56ff61bee6038d284f8316424b5c4f103294bf

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

module Lanyrd
  class Client

    # Specify search term with params.
    # Params include :topic => topic
    def search(query, params = {})
      params = URI.escape(params.collect{|k,v| "#{k}=#{v}"}.join('&')).insert 0, "&"
      get("search/?q=#{query}#{params}")['sections'][0]['rows']
    end

    def popular
      get("search/")['sections'][0]['rows']
    end

    def event(slug, year = Time.now.year)
      get("#{year}/#{slug}/")
    end

    def speakers(slug, year = Time.now.year)
      get("#{year}/#{slug}/speakers/")['sections'][0]['rows']
    end

    def attendees(slug, year = Time.now.year)
      get("#{year}/#{slug}/attendees/")['sections'][0]['rows']
    end

    def schedule(slug, year = Time.now.year)
      get("#{year}/#{slug}/schedule/")['sections'][0]['rows']
    end

    def profile(username)
      get("profile/#{username}/")
    end

    def future_events(username)
      get("profile/#{username}/action/")['events']
    end

    private

    def get(path)
      response = connection.get(path).body
    end

    def connection
      conn = Faraday.new 'http://lanyrd.com/mobile/ios2/' do |conn|
        conn.response :json
        conn.use FaradayMiddleware::Mashify
        conn.adapter Faraday.default_adapter
      end
      conn.headers['X-Lanyrd-Auth'] = Time.now.hash.to_s
      conn
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lanyrd-1.1.1 lib/lanyrd/client.rb