-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapiexemple.rb
48 lines (36 loc) · 1005 Bytes
/
apiexemple.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require 'rubygems'
require 'httparty'
response = HTTParty.get('http://api.stackexchange.com/2.2.questions?site=stackoverflow')
# class EdutechionalResty
# include HTTParty
# base_uri "http://edutechional-resty.herokuapp.com"
# def posts
# self.class.get('/posts.json')
# end
# end
# api = EdutechionalResty.new
# puts api.posts
# class StackExchange
# include HTTParty
# base_uri "http://edutechional-resty.herokuapp.com"
# def initialize(service, page)
# @options = { query: {site: service, page: page}}
# end
# def questions
# self.class.get('/2.2/questions', @options)
# end
# end
class Resty
include HTTParty
base_uri "http://edutechional-resty.herokuapp.com"
def posts
self.class.get('/posts.json')
end
end
# stack_exchange = StackExchange.new('stackoverflow', 1)
# puts stack_exchange.questions
resty = Resty.new
resty_posts = resty.posts
resty_posts.each do |post|
puts "Title: #{post['title']} | Description: #{post['description']}"
end