tanga_services 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 822ad37d54bfe06ddc3a896c8bbf103d5cd37395
4
- data.tar.gz: cff13f02251fdd626e2c2d723a34bf0fc526010b
3
+ metadata.gz: e473f07c6673ce61eb8dd075e0438dd99078c7b4
4
+ data.tar.gz: 0a6aae31f49b38b56c3a1978137232762b564e9f
5
5
  SHA512:
6
- metadata.gz: b98f4c9db57dc52bcbddaea5a2ece7052e633ffdf35330df9e8e55517ddb9f9749a8c8e967c94406db8fff03416757421aa011787197244e0ced2b279d264998
7
- data.tar.gz: 99dd1f2e6e61024c6c556089a41f63feffcd28550b203cf414cb558bf1ccc4231193329163fafe42af206132df0f430ced1abef90e7864056a8ba06217a9750d
6
+ metadata.gz: abfef6ee4062cdb80dbe989bc52a7ff4389c629d3b953120925fc4d60423474776d25d3c5f97b94e86c3054e2aa2cb0a9d06e48dfebc84ca9e06a27453c4e279
7
+ data.tar.gz: d09c8d44cc8a50ca723c6515fa1ac9ac2c5794cf110ec062d75108c7143bea90ebc0a2e19037f2abb8c472ad60707b3d1fdfe5b599c5627b562b7d0b447206b6
data/bin/httparty ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'httparty' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('httparty', 'httparty')
data/bin/safe_yaml ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'safe_yaml' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('safe_yaml', 'safe_yaml')
@@ -0,0 +1,52 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://rawgit.com/joevandyk/a370a1fd94a3e6f88e08/raw/9acc356880ee36e8fd1585db1f1c1582ab3c89ad/bad.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - nginx
23
+ Date:
24
+ - Mon, 31 Aug 2015 21:24:57 GMT
25
+ Content-Type:
26
+ - application/json;charset=utf-8
27
+ Transfer-Encoding:
28
+ - chunked
29
+ Connection:
30
+ - keep-alive
31
+ X-Content-Type-Options:
32
+ - nosniff
33
+ X-Robots-Tag:
34
+ - none
35
+ Rawgit-Naughtiness:
36
+ - '0'
37
+ Access-Control-Allow-Origin:
38
+ - "*"
39
+ Cache-Control:
40
+ - max-age=300
41
+ Etag:
42
+ - W/"6668b30218583639c62a44e0a30ff29a34287f83"
43
+ Vary:
44
+ - Accept-Encoding
45
+ Rawgit-Cache-Status:
46
+ - HIT
47
+ body:
48
+ encoding: ASCII-8BIT
49
+ string: "<html />"
50
+ http_version:
51
+ recorded_at: Mon, 31 Aug 2015 21:24:56 GMT
52
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,33 @@
1
+ require 'httparty'
2
+ require 'http/exceptions'
3
+ require 'json'
4
+
5
+ module TangaServices
6
+ class HTTP
7
+ class Exception < RuntimeError
8
+ end
9
+
10
+ %i( get put delete post ).each do |method|
11
+ define_singleton_method(method) do |*args|
12
+ new(method, *args).call
13
+ end
14
+ end
15
+
16
+ def initialize(method, *args)
17
+ @method = method
18
+ @args = *args
19
+ end
20
+
21
+ def call
22
+ begin
23
+ Http::Exceptions.wrap_and_check do
24
+ response = HTTParty.send(@method, *@args)
25
+ response.parsed_response # See that the response can be accessed
26
+ response
27
+ end
28
+ rescue Http::Exceptions::HttpException, JSON::ParserError
29
+ fail TangaServices::HTTP::Exception
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,3 +1,3 @@
1
1
  module TangaServices
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -1,6 +1,9 @@
1
1
  require "tanga_services/version"
2
2
  require "tanga_services/logger"
3
+ require "tanga_services/http"
3
4
 
4
5
  module TangaServices
5
6
  # Your code goes here...
6
7
  end
8
+
9
+ TS = TangaServices
data/spec/http_spec.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe TS::HTTP do
4
+ %i( get delete post put ).each do |method|
5
+ it method do
6
+ url = 'https://www.tanga.com'
7
+ response = double(parsed_response: 'body', code: 200)
8
+ expect(HTTParty).to receive(method).with(url, options: ['here']) { response }
9
+ body = described_class.send(method, 'https://www.tanga.com', options: ['here'])
10
+ expect(body).to be == response
11
+ end
12
+ end
13
+
14
+ it 'handles json parse error' do
15
+ VCR.use_cassette('invalid json') do
16
+ expect do
17
+ described_class.get('https://rawgit.com/joevandyk/a370a1fd94a3e6f88e08/raw/9acc356880ee36e8fd1585db1f1c1582ab3c89ad/bad.json')
18
+ end.to raise_error(described_class::Exception)
19
+ end
20
+ end
21
+ end
data/spec/spec_helper.rb CHANGED
@@ -2,6 +2,12 @@ require "codeclimate-test-reporter"
2
2
  CodeClimate::TestReporter.start
3
3
 
4
4
  require 'tanga_services'
5
+ require 'vcr'
6
+
7
+ VCR.configure do |c|
8
+ c.cassette_library_dir = 'fixtures/vcr_cassettes'
9
+ c.hook_into :webmock
10
+ end
5
11
 
6
12
  # This file was generated by the `rspec --init` command. Conventionally, all
7
13
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
@@ -18,9 +18,13 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ["lib"]
19
19
 
20
20
  spec.add_dependency 'grape'
21
+ spec.add_dependency 'httparty'
22
+ spec.add_dependency 'tanga-http-exceptions'
21
23
  spec.add_dependency 'activesupport', "> 4"
22
24
 
23
25
  spec.add_development_dependency "bundler", "~> 1.7"
24
26
  spec.add_development_dependency "rake", "~> 10.0"
25
27
  spec.add_development_dependency "rspec", "~> 3.2"
28
+ spec.add_development_dependency "vcr", "~> 2.9"
29
+ spec.add_development_dependency "webmock", "~> 1.21"
26
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tanga_services
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Van Dyk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-20 00:00:00.000000000 Z
11
+ date: 2015-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grape
@@ -24,6 +24,34 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: httparty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: tanga-http-exceptions
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: activesupport
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +108,34 @@ dependencies:
80
108
  - - "~>"
81
109
  - !ruby/object:Gem::Version
82
110
  version: '3.2'
111
+ - !ruby/object:Gem::Dependency
112
+ name: vcr
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.9'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '2.9'
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.21'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.21'
83
139
  description: Read Summary
84
140
  email:
85
141
  - joe@tanga.com
@@ -97,13 +153,18 @@ files:
97
153
  - bin/bundler
98
154
  - bin/cc-tddium-post-worker
99
155
  - bin/htmldiff
156
+ - bin/httparty
100
157
  - bin/ldiff
101
158
  - bin/rackup
102
159
  - bin/rake
103
160
  - bin/rspec
161
+ - bin/safe_yaml
162
+ - fixtures/vcr_cassettes/invalid_json.yml
104
163
  - lib/tanga_services.rb
164
+ - lib/tanga_services/http.rb
105
165
  - lib/tanga_services/logger.rb
106
166
  - lib/tanga_services/version.rb
167
+ - spec/http_spec.rb
107
168
  - spec/logger_spec.rb
108
169
  - spec/spec_helper.rb
109
170
  - tanga_services.gemspec
@@ -132,5 +193,6 @@ signing_key:
132
193
  specification_version: 4
133
194
  summary: Common things shared by tanga services / apps
134
195
  test_files:
196
+ - spec/http_spec.rb
135
197
  - spec/logger_spec.rb
136
198
  - spec/spec_helper.rb