api_recipes 0.7.0 → 2.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,15 +0,0 @@
1
- ## Version 0.6.0 - Default to HTTPS
2
-
3
- **POSSIBLE BREAKING CHANGES**
4
-
5
- Requests now default to HTTPS. If you still want to use (unsecure) HTTP you have to specify it in your configs through the dedicated `protocol` option e.g.
6
-
7
- ```yaml
8
- github:
9
- protocol: http
10
- host: api.github.com
11
- ```
12
-
13
- ## Version 0.5.0 - Better Exceptions
14
-
15
- Exceptions now include attributes that can be accessed during the `rescue` phase in order to execute specific actions
@@ -1,13 +0,0 @@
1
- # Contributor Code of Conduct
2
-
3
- As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
-
5
- We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
-
7
- Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
-
9
- Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
-
11
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
-
13
- This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile DELETED
@@ -1,12 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- gem 'rake', '~> 12.3'
6
-
7
- group :test do
8
- gem 'rspec', '~> 3.8.0'
9
- gem 'guard', '~> 2.15.0'
10
- gem 'guard-rspec', '~> 4.7.3'
11
- gem 'guard-bundler', '~> 2.2.1'
12
- end
data/Guardfile DELETED
@@ -1,14 +0,0 @@
1
- guard :rspec, cmd: 'bundle exec rspec' do
2
- require 'guard/rspec/dsl'
3
- dsl = Guard::RSpec::Dsl.new(self)
4
-
5
- # RSpec files
6
- rspec = dsl.rspec
7
- watch(rspec.spec_helper) { rspec.spec_dir }
8
- watch(rspec.spec_support) { rspec.spec_dir }
9
- watch(rspec.spec_files)
10
-
11
- # Ruby files
12
- ruby = dsl.ruby
13
- dsl.watch_spec_files_for(ruby.lib_files)
14
- end
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
@@ -1,23 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'api_recipes/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'api_recipes'
8
- spec.version = ApiRecipes::VERSION
9
- spec.authors = ['Alessandro Verlato']
10
- spec.email = ['averlato@gmail.com']
11
-
12
- spec.summary = %q{Consume HTTP APIs with style}
13
- spec.homepage = 'https://github.com/madAle/api_recipes'
14
- spec.license = 'MIT'
15
-
16
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
- spec.require_paths = ['lib']
19
- spec.required_ruby_version = '> 2.2.0'
20
-
21
- spec.add_dependency 'oj', '~> 3.7.0'
22
- spec.add_dependency 'http', '~> 4.1.1'
23
- end
Binary file
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "api_recipes"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start
data/bin/setup DELETED
@@ -1,7 +0,0 @@
1
- #!/bin/bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
-
5
- bundle install
6
-
7
- # Do any other automated setup that you need to do here
@@ -1,42 +0,0 @@
1
- require 'api_recipes'
2
- require 'yaml'
3
-
4
- # Configure RemoteApi through a yaml file.
5
- # Take a look at examples/config/apis.yml for details
6
- ApiRecipes.configure do |config|
7
- config.endpoints_configs = YAML.load_file(File.expand_path('examples/config/apis.yml'))
8
- end
9
-
10
- # Let's create a simple class that uses ApiRecipes
11
- class MyFancyClass
12
- include ApiRecipes
13
-
14
- # Declare the endpoints that we're going to use
15
- endpoint :github
16
- end
17
-
18
- # Setup Auth. This will set/replace the HTTP 'Authorization' header with the
19
- # provided value
20
-
21
- # Get your OAUTH token on Github.
22
- # Navigate Profile => Settings => Personal Access Tokens => Generate new token
23
- # Copy the generated string and substitute it to YOUR_GITHUB_OAUTH_TOKEN below
24
- MyFancyClass.github.authorization = 'token YOUR_GITHUB_OAUTH_TOKEN'
25
-
26
- MyFancyClass.github.users.list do |users|
27
- puts users.collect{ |user| user['login'] }
28
- end
29
-
30
- # From now on every MyFancyClass (and its instances) github's api request will
31
- # be authenticated through the provided auth
32
-
33
- # Get user's usernames from Github's Apis (https://github.com)
34
- usernames = nil
35
- MyFancyClass.github.users.list do |users|
36
- usernames = users.collect{ |user| user['login'] }
37
- end
38
-
39
- # Get user's repos
40
- MyFancyClass.github.users.repos(user_id: usernames.first) do |repos|
41
- puts repos
42
- end
@@ -1,41 +0,0 @@
1
- require 'api_recipes'
2
- require 'yaml'
3
-
4
- # Configure RemoteApi through a yaml file.
5
- # Take a look at examples/config/apis.yml for details
6
- ApiRecipes.configure do |config|
7
- config.endpoints_configs = YAML.load_file(File.expand_path('examples/config/apis.yml'))
8
- end
9
-
10
- # Let's create a simple class that uses ApiRecipes
11
- class MyFancyClass
12
- include ApiRecipes
13
-
14
- # Get your OAUTH token on Github.
15
- # Navigate Profile => Settings => Personal Access Tokens => Generate new token
16
- # Copy the generated string and substitute it to YOUR_GITHUB_OAUTH_TOKEN below
17
-
18
- MY_CUSTOM_CONFIG = {
19
- default_headers: {
20
- 'Authorization' => 'token YOUR_GITHUB_OAUTH_TOKEN'
21
- }
22
- }
23
-
24
- # Declare the endpoints that we're going to use
25
- # Add some custom configs
26
- endpoint :github, MY_CUSTOM_CONFIG
27
- end
28
-
29
- # From now on every MyFancyClass (and its instances) github's api request will
30
- # be authenticated through the provided Authorization header
31
-
32
- # Get user's usernames from Github's Apis (https://github.com)
33
- usernames = nil
34
- MyFancyClass.github.users.list do |users|
35
- usernames = users.collect{ |user| user['login'] }
36
- end
37
-
38
- # Get user's repos
39
- MyFancyClass.github.users.repos(user_id: usernames.first) do |repos|
40
- puts repos
41
- end
@@ -1,32 +0,0 @@
1
- require 'api_recipes'
2
- require 'yaml'
3
-
4
- # Configure RemoteApi through a yaml file.
5
- # Take a look at examples/config/apis.yml for details
6
- ApiRecipes.configure do |config|
7
- config.endpoints_configs = YAML.load_file(File.expand_path('examples/config/apis.yml'))
8
- end
9
-
10
- # Let's create a simple class that uses ApiRecipes
11
- class MyFancyClass
12
- include ApiRecipes
13
-
14
- # Declare the endpoints that we're going to use
15
- endpoint :github
16
- end
17
-
18
- # Setup Basic Auth
19
- MyFancyClass.github.basic_auth = { user: 'github_username', pass: 'github_password' }
20
-
21
- # From now on every github's api request will be authenticated with basic auth
22
-
23
- # Get user's usernames from Github's Apis (https://github.com)
24
- usernames = nil
25
- MyFancyClass.github.users.list do |users|
26
- usernames = users.collect{ |user| user['login'] }
27
- end
28
-
29
- # Get user's repos
30
- MyFancyClass.github.users.repos(user_id: usernames.first) do |repos|
31
- puts repos
32
- end
@@ -1,43 +0,0 @@
1
- github:
2
- protocol: https # Optional, defaults to: 'https'
3
- host: api.github.com # Optional, defaults to: 'localhost'
4
- port: 443 # Optional, defaults to: 80 for http and 443 for https
5
- base_path: # Optional, defaults to: ''
6
- api_version: # Optional, defaults to: ''
7
- timeout: 3 # Optional, defaults to: 3 (time expressed in seconds)
8
- on_nok_code: :raise # Optional, defaults to :raise. Possible values: [:do_nothing, :raise, :return_false]
9
- default_headers:
10
- accept: 'application/vnd.github.v3+json'
11
- content_type: 'application/json'
12
-
13
- routes:
14
- users:
15
- list:
16
- path: # Optional, defaults to: ''
17
- method: get # Optional, defaults to: get
18
- ok_code: 200 # Optional, defaults to: 200
19
-
20
- show:
21
- path: /:user_id # You can use :some_param notation and provide the param when calling the route (see examples/simple.rb)
22
-
23
- repos:
24
- path: /:user_id/repos
25
-
26
-
27
- # Example of test endpoint with minimal configuration and multiple routes
28
- jsonplaceholder:
29
- host: jsonplaceholder.typicode.com
30
-
31
- routes:
32
- users:
33
- list:
34
- show:
35
- path: /:user_id # You can use :some_param notation and provide params when calling the route (see examples/simple.rb)
36
-
37
- posts:
38
- list:
39
- show:
40
- path: /:post_id
41
-
42
- comments:
43
- path: /:post_id/comments
@@ -1,51 +0,0 @@
1
- # This example aims to demonstrate how to provide custom configs to endpoints
2
-
3
- require 'api_recipes'
4
-
5
- # Configure RemoteApi through custom settings
6
- FAKE_API_SETTINGS = {
7
- host: 'jsonplaceholder.typicode.com',
8
- timeout: 10,
9
- routes: {
10
- users: {
11
- list: nil,
12
- show: {
13
- path: '/:user_id'
14
- }
15
- },
16
- posts: {
17
- list: nil,
18
- comments: {
19
- path: '/:post_id/comments'
20
- }
21
- }
22
- }
23
- }
24
-
25
- # Let's create a simple class that uses ApiRecipes
26
- class MyFancyClass
27
- include ApiRecipes
28
-
29
- # Declare the endpoints that we're going to use
30
- endpoint :fake_api, FAKE_API_SETTINGS
31
- end
32
-
33
- # Let's demonstrate that even a class instance can use enpoints
34
- fancy_instance = MyFancyClass.new
35
-
36
- # Get User's names
37
- fancy_instance.fake_api.users.list do |users|
38
- names = users.collect{ |user| user['name'] }
39
- puts "Names: #{names}"
40
- end
41
-
42
- # Collect post ids
43
- post_ids = nil
44
- MyFancyClass.fake_api.posts.list do |posts|
45
- post_ids = posts.map{ |post| post['id'] }
46
- end
47
-
48
- # Fetch post's comments
49
- fancy_instance.fake_api.posts.comments(post_id: post_ids.last) do |comments|
50
- puts "Comments: #{comments}"
51
- end
@@ -1,21 +0,0 @@
1
- require 'api_recipes'
2
- require 'yaml'
3
-
4
- ApiRecipes.configure do |config|
5
- config.endpoints_configs = YAML.load_file(File.expand_path('examples/config/apis.yml'))
6
- end
7
-
8
- class Foo
9
- include ApiRecipes
10
-
11
- endpoint :jsonplaceholder
12
- end
13
-
14
- puts 'Use from class:'
15
- puts Foo.jsonplaceholder.users.list
16
-
17
- f1 = Foo.new
18
-
19
- puts "\n\nUse from instance:"
20
- sleep 1
21
- puts f1.jsonplaceholder.users.list
@@ -1,54 +0,0 @@
1
- require 'api_recipes'
2
- require 'yaml'
3
-
4
- # Configure RemoteApi through a yaml file.
5
- # Take a look at examples/config/apis.yml for details
6
- ApiRecipes.configure do |config|
7
- config.endpoints_configs = YAML.load_file(File.expand_path('examples/config/apis.yml'))
8
- end
9
-
10
- # Let's create a simple class that uses ApiRecipes
11
- class MyFancyClass
12
- include ApiRecipes
13
-
14
- # Declare the endpoints that we're going to use
15
- endpoint :jsonplaceholder
16
- endpoint :github
17
- end
18
-
19
- # Get users from JSONPlaceholder (http://jsonplaceholder.typicode.com/users)
20
- MyFancyClass.jsonplaceholder.users.list do |users|
21
- puts 'Usernames:'
22
- puts users.collect{ |user| user['name'] }
23
- end
24
-
25
- # Get posts from JSONPlaceholder (http://jsonplaceholder.typicode.com/posts)
26
- post_ids = nil
27
- MyFancyClass.jsonplaceholder.posts.list do |posts|
28
- post_ids = posts.map{ |post| post['id'] }
29
- end
30
-
31
- puts "\n\n\n\n"
32
- # Get first post's comments from JSONPlaceholder
33
- # http://jsonplaceholder.typicode.com/posts/1/comments
34
- MyFancyClass.jsonplaceholder.posts.comments(post_id: post_ids.first) do |comments|
35
- puts "Comments:"
36
- puts comments
37
- end
38
-
39
- puts "\n\n\n\n"
40
- # Get also Github users
41
- # Warning: Github has a low rate limit for unauthorized api requests.
42
- MyFancyClass.github.users.list do |body, status_code, status_message|
43
- puts "Response: #{status_code}: #{status_message}"
44
- puts "Data: #{body}"
45
- end
46
-
47
- # If you need a 'raw' response (e.g. the response must not automatically be
48
- # parsed as JSON) just don't provide a block and the result will be an
49
- # HTTP::Response object. See https://github.com/httprb/http for further details
50
-
51
- response = MyFancyClass.github.users.list
52
- puts response.code # e.g. 200
53
- puts response.reason # e.g. OK
54
- puts response.body # e.g Some response body (not necessarely JSON)
@@ -1,38 +0,0 @@
1
- require 'api_recipes'
2
- require 'yaml'
3
-
4
- # Configure RemoteApi through a yaml file.
5
- # Take a look at examples/config/apis.yml for details
6
- ApiRecipes.configure do |config|
7
- config.endpoints_configs = YAML.load_file(File.expand_path('examples/config/apis.yml'))
8
- end
9
-
10
- # Let's create a simple class that uses ApiRecipes
11
- class MyFancyClass
12
- include ApiRecipes
13
-
14
- endpoint :github
15
- end
16
-
17
-
18
- # Warning: Github has a low rate limit for unauthorized api requests.
19
-
20
-
21
- # Get user's usernames from Github's Apis (https://github.com)
22
- usernames = nil
23
-
24
- MyFancyClass.github.users.list do |users|
25
- usernames = users.collect{ |user| user['login'] }
26
- end
27
-
28
- # Get user's repos
29
- MyFancyClass.github.users.repos(user_id: usernames.first) do |repos|
30
- puts repos
31
- end
32
-
33
- # The endpoints are available on instances too
34
- fancy = MyFancyClass.new
35
-
36
- fancy.github.users.list do |users|
37
- puts users.collect{ |user| user['login'] }
38
- end