aylien_text_api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -0
  3. data/Gemfile +3 -0
  4. data/Gemfile.lock +28 -0
  5. data/LICENSE +13 -0
  6. data/README.md +67 -0
  7. data/Rakefile +8 -0
  8. data/aylien_text_api.gemspec +24 -0
  9. data/config/app_config.yml.example +7 -0
  10. data/lib/aylien_text_api.rb +23 -0
  11. data/lib/aylien_text_api/client.rb +246 -0
  12. data/lib/aylien_text_api/configuration.rb +57 -0
  13. data/lib/aylien_text_api/connection.rb +71 -0
  14. data/lib/aylien_text_api/error.rb +110 -0
  15. data/lib/aylien_text_api/version.rb +17 -0
  16. data/spec/fixtures/aylien_text_api/client/classify_with_invalid_client.yml +36 -0
  17. data/spec/fixtures/aylien_text_api/client/classify_with_invalid_params.yml +40 -0
  18. data/spec/fixtures/aylien_text_api/client/classify_with_text.yml +48 -0
  19. data/spec/fixtures/aylien_text_api/client/classify_with_unauthenticated_client.yml +40 -0
  20. data/spec/fixtures/aylien_text_api/client/classify_with_valid_url.yml +98 -0
  21. data/spec/fixtures/aylien_text_api/client/classify_with_value_as_text.yml +48 -0
  22. data/spec/fixtures/aylien_text_api/client/classify_with_value_as_valid_url.yml +98 -0
  23. data/spec/fixtures/aylien_text_api/client/concepts_with_invalid_client.yml +36 -0
  24. data/spec/fixtures/aylien_text_api/client/concepts_with_invalid_params.yml +40 -0
  25. data/spec/fixtures/aylien_text_api/client/concepts_with_text.yml +44 -0
  26. data/spec/fixtures/aylien_text_api/client/concepts_with_unauthenticated_client.yml +40 -0
  27. data/spec/fixtures/aylien_text_api/client/concepts_with_valid_url.yml +63 -0
  28. data/spec/fixtures/aylien_text_api/client/concepts_with_value_as_text.yml +44 -0
  29. data/spec/fixtures/aylien_text_api/client/concepts_with_value_as_valid_url.yml +63 -0
  30. data/spec/fixtures/aylien_text_api/client/entities_with_invalid_client.yml +36 -0
  31. data/spec/fixtures/aylien_text_api/client/entities_with_invalid_params.yml +40 -0
  32. data/spec/fixtures/aylien_text_api/client/entities_with_text.yml +43 -0
  33. data/spec/fixtures/aylien_text_api/client/entities_with_unauthenticated_client.yml +40 -0
  34. data/spec/fixtures/aylien_text_api/client/entities_with_valid_url.yml +302 -0
  35. data/spec/fixtures/aylien_text_api/client/entities_with_value_as_text.yml +43 -0
  36. data/spec/fixtures/aylien_text_api/client/entities_with_value_as_valid_url.yml +302 -0
  37. data/spec/fixtures/aylien_text_api/client/extract_with_invalid_client.yml +36 -0
  38. data/spec/fixtures/aylien_text_api/client/extract_with_invalid_params.yml +40 -0
  39. data/spec/fixtures/aylien_text_api/client/extract_with_unauthenticated_client.yml +40 -0
  40. data/spec/fixtures/aylien_text_api/client/extract_with_valid_url.yml +185 -0
  41. data/spec/fixtures/aylien_text_api/client/extract_with_value_as_text.yml +40 -0
  42. data/spec/fixtures/aylien_text_api/client/extract_with_value_as_valid_url.yml +185 -0
  43. data/spec/fixtures/aylien_text_api/client/hashtags_with_invalid_client.yml +36 -0
  44. data/spec/fixtures/aylien_text_api/client/hashtags_with_invalid_params.yml +40 -0
  45. data/spec/fixtures/aylien_text_api/client/hashtags_with_text.yml +48 -0
  46. data/spec/fixtures/aylien_text_api/client/hashtags_with_unauthenticated_client.yml +40 -0
  47. data/spec/fixtures/aylien_text_api/client/hashtags_with_valid_url.yml +58 -0
  48. data/spec/fixtures/aylien_text_api/client/hashtags_with_value_as_text.yml +48 -0
  49. data/spec/fixtures/aylien_text_api/client/hashtags_with_value_as_valid_url.yml +58 -0
  50. data/spec/fixtures/aylien_text_api/client/language_with_invalid_client.yml +36 -0
  51. data/spec/fixtures/aylien_text_api/client/language_with_invalid_params.yml +40 -0
  52. data/spec/fixtures/aylien_text_api/client/language_with_unauthenticated_client.yml +40 -0
  53. data/spec/fixtures/aylien_text_api/client/language_with_valid_text.yml +41 -0
  54. data/spec/fixtures/aylien_text_api/client/language_with_valid_url.yml +57 -0
  55. data/spec/fixtures/aylien_text_api/client/language_with_value_as_text.yml +41 -0
  56. data/spec/fixtures/aylien_text_api/client/language_with_value_as_valid_url.yml +57 -0
  57. data/spec/fixtures/aylien_text_api/client/related_with_invalid_client.yml +36 -0
  58. data/spec/fixtures/aylien_text_api/client/related_with_invalid_params.yml +40 -0
  59. data/spec/fixtures/aylien_text_api/client/related_with_phrase.yml +60 -0
  60. data/spec/fixtures/aylien_text_api/client/related_with_unauthenticated_client.yml +40 -0
  61. data/spec/fixtures/aylien_text_api/client/related_with_value_as_phrase.yml +60 -0
  62. data/spec/fixtures/aylien_text_api/client/related_with_value_as_valid_url.yml +40 -0
  63. data/spec/fixtures/aylien_text_api/client/sentiment_with_invalid_client.yml +36 -0
  64. data/spec/fixtures/aylien_text_api/client/sentiment_with_invalid_params.yml +40 -0
  65. data/spec/fixtures/aylien_text_api/client/sentiment_with_text.yml +53 -0
  66. data/spec/fixtures/aylien_text_api/client/sentiment_with_unauthenticated_client.yml +40 -0
  67. data/spec/fixtures/aylien_text_api/client/sentiment_with_valid_url.yml +57 -0
  68. data/spec/fixtures/aylien_text_api/client/sentiment_with_value_as_text.yml +53 -0
  69. data/spec/fixtures/aylien_text_api/client/sentiment_with_value_as_valid_url.yml +57 -0
  70. data/spec/fixtures/aylien_text_api/client/summarize_with_invalid_client.yml +36 -0
  71. data/spec/fixtures/aylien_text_api/client/summarize_with_invalid_params.yml +41 -0
  72. data/spec/fixtures/aylien_text_api/client/summarize_with_title_and_text.yml +78 -0
  73. data/spec/fixtures/aylien_text_api/client/summarize_with_unauthenticated_client.yml +40 -0
  74. data/spec/fixtures/aylien_text_api/client/summarize_with_valid_url.yml +65 -0
  75. data/spec/fixtures/aylien_text_api/client/summarize_with_value_as_text_and_title.yml +78 -0
  76. data/spec/fixtures/aylien_text_api/client/summarize_with_value_as_text_and_without_title.yml +41 -0
  77. data/spec/fixtures/aylien_text_api/client/summarize_with_value_as_valid_url.yml +65 -0
  78. data/spec/lib/aylien_text_api/classify.rb +86 -0
  79. data/spec/lib/aylien_text_api/client_spec.rb +23 -0
  80. data/spec/lib/aylien_text_api/concepts.rb +81 -0
  81. data/spec/lib/aylien_text_api/entities.rb +81 -0
  82. data/spec/lib/aylien_text_api/extract.rb +81 -0
  83. data/spec/lib/aylien_text_api/hashtags.rb +87 -0
  84. data/spec/lib/aylien_text_api/language.rb +79 -0
  85. data/spec/lib/aylien_text_api/related.rb +80 -0
  86. data/spec/lib/aylien_text_api/sentiment.rb +91 -0
  87. data/spec/lib/aylien_text_api/summarize.rb +95 -0
  88. data/spec/spec_helper.rb +16 -0
  89. metadata +193 -0
@@ -0,0 +1,81 @@
1
+ describe "Entities endpoint" do
2
+ before do
3
+ @url = "http://www.businessinsider.com/carl-icahn-open-letter-to-apple-2014-1"
4
+ @text = %q(Barack Hussein Obama II is the 44th and current
5
+ President of the United States, and the first
6
+ African American to hold the office.)
7
+ end
8
+
9
+ it "shouldn't be nil with valid url" do
10
+ VCR.use_cassette('entities_with_valid_url') do
11
+ result = @client.entities(url: @url)
12
+ result.wont_be_nil
13
+ end
14
+ end
15
+
16
+ it "shouldn't be nil with text" do
17
+ VCR.use_cassette('entities_with_text') do
18
+ result = @client.entities(text: @text)
19
+ result.wont_be_nil
20
+ end
21
+ end
22
+
23
+ it "shouldn't be nil with value as valid url" do
24
+ VCR.use_cassette('entities_with_value_as_valid_url') do
25
+ result = @client.entities(@url)
26
+ result.wont_be_nil
27
+ end
28
+ end
29
+
30
+ it "shouldn't be nil with value as text" do
31
+ VCR.use_cassette('entities_with_value_as_text') do
32
+ result = @client.entities(@text)
33
+ result.wont_be_nil
34
+ end
35
+ end
36
+
37
+ it "should be nil with unauthenticated client" do
38
+ VCR.use_cassette('entities_with_unauthenticated_client') do
39
+ result = @unauthenticated_client.entities(text: @text)
40
+ result.must_be_nil
41
+ end
42
+ end
43
+
44
+ it "should raise Forbidden with unauthenticated client" do
45
+ VCR.use_cassette('entities_with_unauthenticated_client') do
46
+ proc {
47
+ @unauthenticated_client.entities!(text: @text)
48
+ }.must_raise AylienTextApi::Error::Forbidden
49
+ end
50
+ end
51
+
52
+ it "should be nil with invalid client" do
53
+ VCR.use_cassette('entities_with_invalid_client') do
54
+ result = @invalid_client.entities(text: @text)
55
+ result.must_be_nil
56
+ end
57
+ end
58
+
59
+ it "should raise Forbidden with invalid client" do
60
+ VCR.use_cassette('entities_with_invalid_client') do
61
+ proc {
62
+ @invalid_client.entities!(text: @text)
63
+ }.must_raise AylienTextApi::Error::Forbidden
64
+ end
65
+ end
66
+
67
+ it "should be nil with invalid params" do
68
+ VCR.use_cassette('entities_with_invalid_params') do
69
+ result = @client.entities(wrong_param: @text)
70
+ result.must_be_nil
71
+ end
72
+ end
73
+
74
+ it "should raise BadRequest with invalid params" do
75
+ VCR.use_cassette('entities_with_invalid_params') do
76
+ proc {
77
+ @client.entities!(wrong_param: @text)
78
+ }.must_raise AylienTextApi::Error::BadRequest
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,81 @@
1
+ describe "Extract endpoint" do
2
+ before do
3
+ @url = "http://www.bbc.com/sport/0/football/30180206"
4
+ @text = %q(The oil-rich billionaires of the Gulf have planted
5
+ a flag at the heart of the sporting landscape in recent years.)
6
+ end
7
+
8
+ it "shouldn't be nil with valid url" do
9
+ VCR.use_cassette('extract_with_valid_url') do
10
+ result = @client.extract(url: @url)
11
+ result.wont_be_nil
12
+ end
13
+ end
14
+
15
+ it "shouldn't be nil with value as valid url" do
16
+ VCR.use_cassette('extract_with_value_as_valid_url') do
17
+ result = @client.extract(@url)
18
+ result.wont_be_nil
19
+ end
20
+ end
21
+
22
+ it "should be nil with invalid params" do
23
+ VCR.use_cassette('extract_with_invalid_params') do
24
+ result = @client.extract(text: @text)
25
+ result.must_be_nil
26
+ end
27
+ end
28
+
29
+ it "should be nil with value as text" do
30
+ VCR.use_cassette('extract_with_value_as_text') do
31
+ result = @client.extract(@text)
32
+ result.must_be_nil
33
+ end
34
+ end
35
+
36
+ it "should be nil with unauthenticated client" do
37
+ VCR.use_cassette('extract_with_unauthenticated_client') do
38
+ result = @unauthenticated_client.extract(url: @url)
39
+ result.must_be_nil
40
+ end
41
+ end
42
+
43
+ it "should raise Forbidden with unauthenticated client" do
44
+ VCR.use_cassette('extract_with_unauthenticated_client') do
45
+ proc {
46
+ @unauthenticated_client.extract!(url: @url)
47
+ }.must_raise AylienTextApi::Error::Forbidden
48
+ end
49
+ end
50
+
51
+ it "should be nil with invalid client" do
52
+ VCR.use_cassette('extract_with_invalid_client') do
53
+ result = @invalid_client.extract(url: @url)
54
+ result.must_be_nil
55
+ end
56
+ end
57
+
58
+ it "should raise Forbidden with invalid client" do
59
+ VCR.use_cassette('extract_with_invalid_client') do
60
+ proc {
61
+ @invalid_client.extract!(url: @url)
62
+ }.must_raise AylienTextApi::Error::Forbidden
63
+ end
64
+ end
65
+
66
+ it "should raise BadRequest with value as text" do
67
+ VCR.use_cassette('extract_with_value_as_text') do
68
+ proc {
69
+ @client.extract!(@text)
70
+ }.must_raise AylienTextApi::Error::BadRequest
71
+ end
72
+ end
73
+
74
+ it "should raise BadRequest with invalid params" do
75
+ VCR.use_cassette('extract_with_invalid_params') do
76
+ proc {
77
+ @client.extract!(wrong_param: @text)
78
+ }.must_raise AylienTextApi::Error::BadRequest
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,87 @@
1
+ # encoding: utf-8
2
+
3
+ describe "Hashtags endpoint" do
4
+ before do
5
+ @url = "http://www.bbc.com/sport/0/football/25912393"
6
+ @text = %q(The Google Cast SDK is simple to integrate because there’s no
7
+ need to write a new app. Just incorporate the SDK into your existing
8
+ mobile and web apps to bring your content to the TV. You are in
9
+ control of how and when you develop and publish your cast-ready
10
+ apps through the Google Cast developer console.
11
+ The SDK is available on Android and iOS as well as on Chrome
12
+ through the Google Cast browser extension.)
13
+ end
14
+
15
+ it "shouldn't be nil with valid url" do
16
+ VCR.use_cassette('hashtags_with_valid_url') do
17
+ result = @client.hashtags(url: @url)
18
+ result.wont_be_nil
19
+ end
20
+ end
21
+
22
+ it "shouldn't be nil with text" do
23
+ VCR.use_cassette('hashtags_with_text') do
24
+ result = @client.hashtags(text: @text)
25
+ result.wont_be_nil
26
+ end
27
+ end
28
+
29
+ it "shouldn't be nil with value as text" do
30
+ VCR.use_cassette('hashtags_with_value_as_text') do
31
+ result = @client.hashtags(@text)
32
+ result.wont_be_nil
33
+ end
34
+ end
35
+
36
+ it "shouldn't be nil with value as valid url" do
37
+ VCR.use_cassette('hashtags_with_value_as_valid_url') do
38
+ result = @client.hashtags(@url)
39
+ result.wont_be_nil
40
+ end
41
+ end
42
+
43
+ it "should be nil with unauthenticated client" do
44
+ VCR.use_cassette('hashtags_with_unauthenticated_client') do
45
+ result = @unauthenticated_client.hashtags(text: @text)
46
+ result.must_be_nil
47
+ end
48
+ end
49
+
50
+ it "should raise Forbidden with unauthenticated client" do
51
+ VCR.use_cassette('hashtags_with_unauthenticated_client') do
52
+ proc {
53
+ @unauthenticated_client.hashtags!(text: @text)
54
+ }.must_raise AylienTextApi::Error::Forbidden
55
+ end
56
+ end
57
+
58
+ it "should be nil with invalid client" do
59
+ VCR.use_cassette('hashtags_with_invalid_client') do
60
+ result = @invalid_client.hashtags(text: @text)
61
+ result.must_be_nil
62
+ end
63
+ end
64
+
65
+ it "should raise Forbidden with invalid client" do
66
+ VCR.use_cassette('hashtags_with_invalid_client') do
67
+ proc {
68
+ @invalid_client.hashtags!(text: @text)
69
+ }.must_raise AylienTextApi::Error::Forbidden
70
+ end
71
+ end
72
+
73
+ it "should be nil with invalid params" do
74
+ VCR.use_cassette('hashtags_with_invalid_params') do
75
+ result = @client.hashtags(wrong_param: @text)
76
+ result.must_be_nil
77
+ end
78
+ end
79
+
80
+ it "should raise BadRequest with invalid params" do
81
+ VCR.use_cassette('hashtags_with_invalid_params') do
82
+ proc {
83
+ @client.hashtags!(wrong_param: @text)
84
+ }.must_raise AylienTextApi::Error::BadRequest
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,79 @@
1
+ describe "Language endpoint" do
2
+ before do
3
+ @url = "http://www.bbc.com/sport/0/football/25912393"
4
+ @text = %q(Hello there! How's it going?)
5
+ end
6
+
7
+ it "shouldn't be nil with valid url" do
8
+ VCR.use_cassette('language_with_valid_url') do
9
+ result = @client.language(url: @url)
10
+ result.wont_be_nil
11
+ end
12
+ end
13
+
14
+ it "shouldn't be nil with valid text" do
15
+ VCR.use_cassette('language_with_valid_text') do
16
+ result = @client.language(text: @text)
17
+ result.wont_be_nil
18
+ end
19
+ end
20
+
21
+ it "shouldn't be nil with value as text" do
22
+ VCR.use_cassette('language_with_value_as_text') do
23
+ result = @client.language(@text)
24
+ result.wont_be_nil
25
+ end
26
+ end
27
+
28
+ it "shouldn't be nil with value as valid url" do
29
+ VCR.use_cassette('language_with_value_as_valid_url') do
30
+ result = @client.language(@url)
31
+ result.wont_be_nil
32
+ end
33
+ end
34
+
35
+ it "should be nil with unauthenticated client" do
36
+ VCR.use_cassette('language_with_unauthenticated_client') do
37
+ result = @unauthenticated_client.language(text: @text)
38
+ result.must_be_nil
39
+ end
40
+ end
41
+
42
+ it "should raise Forbidden with unauthenticated client" do
43
+ VCR.use_cassette('language_with_unauthenticated_client') do
44
+ proc {
45
+ @unauthenticated_client.language!(text: @text)
46
+ }.must_raise AylienTextApi::Error::Forbidden
47
+ end
48
+ end
49
+
50
+ it "should be nil with invalid client" do
51
+ VCR.use_cassette('language_with_invalid_client') do
52
+ result = @invalid_client.language(text: @text)
53
+ result.must_be_nil
54
+ end
55
+ end
56
+
57
+ it "should raise Forbidden with invalid client" do
58
+ VCR.use_cassette('language_with_invalid_client') do
59
+ proc {
60
+ @invalid_client.language!(text: @text)
61
+ }.must_raise AylienTextApi::Error::Forbidden
62
+ end
63
+ end
64
+
65
+ it "should be nil with invalid params" do
66
+ VCR.use_cassette('language_with_invalid_params') do
67
+ result = @client.language(wrong_param: @text)
68
+ result.must_be_nil
69
+ end
70
+ end
71
+
72
+ it "should raise BadRequest with invalid params" do
73
+ VCR.use_cassette('language_with_invalid_params') do
74
+ proc {
75
+ @client.language!(wrong_param: @text)
76
+ }.must_raise AylienTextApi::Error::BadRequest
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,80 @@
1
+ describe "Related endpoint" do
2
+ before do
3
+ @phrase = "android"
4
+ @url = "http://www.bbc.com/sport/0/football/25912393"
5
+ end
6
+
7
+ it "shouldn't be nil with phrase" do
8
+ VCR.use_cassette('related_with_phrase') do
9
+ result = @client.related(phrase: @phrase)
10
+ result.wont_be_nil
11
+ end
12
+ end
13
+
14
+ it "shouldn't be nil with value as phrase" do
15
+ VCR.use_cassette('related_with_value_as_phrase') do
16
+ result = @client.related(@phrase)
17
+ result.wont_be_nil
18
+ end
19
+ end
20
+
21
+ it "should be nil with value as valid url" do
22
+ VCR.use_cassette('related_with_value_as_valid_url') do
23
+ result = @client.related(@url)
24
+ result.must_be_nil
25
+ end
26
+ end
27
+
28
+ it "should be nil with invalid params" do
29
+ VCR.use_cassette('related_with_invalid_params') do
30
+ result = @client.related(wrong_param: @phrase)
31
+ result.must_be_nil
32
+ end
33
+ end
34
+
35
+ it "should be nil with unauthenticated client" do
36
+ VCR.use_cassette('related_with_unauthenticated_client') do
37
+ result = @unauthenticated_client.related(phrase: @phrase)
38
+ result.must_be_nil
39
+ end
40
+ end
41
+
42
+ it "should raise Forbidden with unauthenticated client" do
43
+ VCR.use_cassette('related_with_unauthenticated_client') do
44
+ proc {
45
+ @unauthenticated_client.related!(phrase: @phrase)
46
+ }.must_raise AylienTextApi::Error::Forbidden
47
+ end
48
+ end
49
+
50
+ it "should be nil with invalid client" do
51
+ VCR.use_cassette('related_with_invalid_client') do
52
+ result = @invalid_client.related(phrase: @phrase)
53
+ result.must_be_nil
54
+ end
55
+ end
56
+
57
+ it "should raise Forbidden with invalid client" do
58
+ VCR.use_cassette('related_with_invalid_client') do
59
+ proc {
60
+ @invalid_client.related!(phrase: @phrase)
61
+ }.must_raise AylienTextApi::Error::Forbidden
62
+ end
63
+ end
64
+
65
+ it "should raise BadRequest with value as valid url" do
66
+ VCR.use_cassette('related_with_value_as_valid_url') do
67
+ proc {
68
+ @client.related!(@url)
69
+ }.must_raise AylienTextApi::Error::BadRequest
70
+ end
71
+ end
72
+
73
+ it "should raise BadRequest with invalid params" do
74
+ VCR.use_cassette('related_with_invalid_params') do
75
+ proc {
76
+ @client.related!(wrong_param: @text)
77
+ }.must_raise AylienTextApi::Error::BadRequest
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,91 @@
1
+ describe "Sentiment endpoint" do
2
+ before do
3
+ @url = "http://www.bbc.com/sport/0/football/25912393"
4
+ @text = %q(I really enjoyed using the Canon Ixus in Madrid.
5
+ The Panasonic Lumix is a poor camera, but the Canon Ixus is really sleek.
6
+ The Canon Ixus is much better than the Panasonic Lumix.
7
+ All I want to do with a camera is point it and then just press the button.
8
+ The Canon Ixus is perfect for that. You will soon get great photos
9
+ with very little effort. I had previously returned a Panasonic Lumix
10
+ because the pictures were not of the quality I expected.
11
+ Spending the money on the Canon was a smart move.
12
+ I would recommend the Ixus to anyone without hesitation.
13
+ Two small issues to be pointed out: firstly, the battery
14
+ life is not fantastic. Also, the zoom is not very powerful.
15
+ If your subject is far away, you should not expect good results.
16
+ Review made by John Irving from Florida.)
17
+ end
18
+
19
+ it "shouldn't be nil with valid url" do
20
+ VCR.use_cassette('sentiment_with_valid_url') do
21
+ result = @client.sentiment(url: @url)
22
+ result.wont_be_nil
23
+ end
24
+ end
25
+
26
+ it "shouldn't be nil with text" do
27
+ VCR.use_cassette('sentiment_with_text') do
28
+ result = @client.sentiment(text: @text)
29
+ result.wont_be_nil
30
+ end
31
+ end
32
+
33
+ it "shouldn't be nil with value as text" do
34
+ VCR.use_cassette('sentiment_with_value_as_text') do
35
+ result = @client.sentiment(@text)
36
+ result.wont_be_nil
37
+ end
38
+ end
39
+
40
+ it "shouldn't be nil with value as valid url" do
41
+ VCR.use_cassette('sentiment_with_value_as_valid_url') do
42
+ result = @client.sentiment(@url)
43
+ result.wont_be_nil
44
+ end
45
+ end
46
+
47
+ it "should be nil with unauthenticated client" do
48
+ VCR.use_cassette('sentiment_with_unauthenticated_client') do
49
+ result = @unauthenticated_client.sentiment(text: @text)
50
+ result.must_be_nil
51
+ end
52
+ end
53
+
54
+ it "should raise Forbidden with unauthenticated client" do
55
+ VCR.use_cassette('sentiment_with_unauthenticated_client') do
56
+ proc {
57
+ @unauthenticated_client.sentiment!(text: @text)
58
+ }.must_raise AylienTextApi::Error::Forbidden
59
+ end
60
+ end
61
+
62
+ it "should be nil with invalid client" do
63
+ VCR.use_cassette('sentiment_with_invalid_client') do
64
+ result = @invalid_client.sentiment(text: @text)
65
+ result.must_be_nil
66
+ end
67
+ end
68
+
69
+ it "should raise Forbidden with invalid client" do
70
+ VCR.use_cassette('sentiment_with_invalid_client') do
71
+ proc {
72
+ @invalid_client.sentiment!(text: @text)
73
+ }.must_raise AylienTextApi::Error::Forbidden
74
+ end
75
+ end
76
+
77
+ it "should be nil with invalid params" do
78
+ VCR.use_cassette('sentiment_with_invalid_params') do
79
+ result = @client.sentiment(wrong_param: @text)
80
+ result.must_be_nil
81
+ end
82
+ end
83
+
84
+ it "should raise BadRequest with invalid params" do
85
+ VCR.use_cassette('sentiment_with_invalid_params') do
86
+ proc {
87
+ @client.sentiment!(wrong_param: @text)
88
+ }.must_raise AylienTextApi::Error::BadRequest
89
+ end
90
+ end
91
+ end