Skip to content
This repository

Echo API #277

Closed
wants to merge 2 commits into from

2 participants

Alexander Petrovsky Pablo Fernandez
Pablo Fernandez

How can this even work when every endpoint returns null?

Pablo Fernandez

Ok, I'll add some comments inline.

src/main/java/org/scribe/builder/api/EchoApi.java
... ...
@@ -0,0 +1,23 @@
  1
+package org.scribe.builder.api;
  2
+
  3
+import org.scribe.model.*;
  4
+import org.scribe.builder.api.DefaultApi10a;
  5
+
  6
+
  7
+public class EchoApi extends DefaultApi10a {
1
Pablo Fernandez Owner

always open the braces on the following line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/main/java/org/scribe/builder/api/EchoApi.java
... ...
@@ -0,0 +1,23 @@
  1
+package org.scribe.builder.api;
  2
+
  3
+import org.scribe.model.*;
  4
+import org.scribe.builder.api.DefaultApi10a;
1
Pablo Fernandez Owner

all imports should be with a star, eg:

import java.util.*

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/main/java/org/scribe/builder/api/EchoApi.java
((5 lines not shown))
  5
+
  6
+
  7
+public class EchoApi extends DefaultApi10a {
  8
+  @Override
  9
+  public String getAccessTokenEndpoint() {
  10
+    return null;
  11
+  }
  12
+
  13
+  @Override
  14
+  public String getAuthorizationUrl(Token requestToken) {
  15
+    return null;
  16
+  }
  17
+
  18
+  @Override
  19
+  public String getRequestTokenEndpoint() {
  20
+    return null;
1
Pablo Fernandez Owner

Never return null.

Instead throw an exception, like:

throw new OAuthException("Echo Api only supports two legged OAuth calls");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/test/java/org/scribe/examples/EchoExample.java
((10 lines not shown))
  10
+/**
  11
+ * @author Alexander M. Petrovsky <askjuise@gmail.com>
  12
+ * @since 07.06.2012
  13
+ */
  14
+public class EchoExample
  15
+{
  16
+  private static final String PROTECTED_RESOURCE_URL = "http://api.echoenabled.com/v1/submit";
  17
+
  18
+  public static void main(String[] args)
  19
+  {
  20
+    // Replace these with your own api key and secret
  21
+    final String key = "your key";
  22
+    final String secret = "your secret";
  23
+
  24
+    Token token = new Token("", "");
  25
+    OAuthService service = new ServiceBuilder().apiKey(key).apiSecret(secret).provider(ECHOApi.class).build();
3
Pablo Fernandez Owner

The class is named EchoApi but here you use ECHOApi.

This code won't compile

Alexander Petrovsky
juise added a note

Ok, I'll fix my mistakes, thank you

Pablo Fernandez Owner

I wouldn't call them mistakes, they are mostly style changes (but this one)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Alexander Petrovsky
juise commented

Do you can check my little changes for merge with your repo?

Pablo Fernandez fernandezpablo85 closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Jun 07, 2012
Alexander Petrovsky Add Echo http://aboutecho.com/ support 79f4ec4
Jun 08, 2012
Alexander Petrovsky little bug fix and code styling f05fd13
This page is out of date. Refresh to see the latest.
25  src/main/java/org/scribe/builder/api/EchoApi.java
... ...
@@ -0,0 +1,25 @@
  1
+package org.scribe.builder.api;
  2
+
  3
+import org.scribe.model.*;
  4
+
  5
+public class EchoApi extends DefaultApi10a
  6
+{
  7
+  @Override
  8
+  public String getAccessTokenEndpoint()
  9
+  {
  10
+    throw new OAuthException("Echo API only supports 2-legged OAuth calls");
  11
+  }
  12
+
  13
+  @Override
  14
+  public String getAuthorizationUrl(Token requestToken)
  15
+  {
  16
+    throw new OAuthException("Echo API only supports 2-legged OAuth calls");
  17
+  }
  18
+
  19
+  @Override
  20
+  public String getRequestTokenEndpoint()
  21
+  {
  22
+    throw new OAuthException("Echo API only supports 2-legged OAuth calls");
  23
+  }
  24
+}
  25
+
40  src/test/java/org/scribe/examples/EchoExample.java
... ...
@@ -0,0 +1,40 @@
  1
+package org.scribe.examples;
  2
+
  3
+import java.util.*;
  4
+import org.scribe.builder.*;
  5
+import org.scribe.builder.api.*;
  6
+import org.scribe.model.*;
  7
+import org.scribe.oauth.*;
  8
+
  9
+/**
  10
+ * @author Alexander M. Petrovsky <askjuise@gmail.com>
  11
+ * @since 07.06.2012
  12
+ */
  13
+public class EchoExample
  14
+{
  15
+  private static final String PROTECTED_RESOURCE_URL = "http://api.echoenabled.com/v1/submit";
  16
+
  17
+  public static void main(String[] args)
  18
+  {
  19
+    // Replace these with your own api key and secret
  20
+    final String key = "your key";
  21
+    final String secret = "your secret";
  22
+
  23
+    // In 2-legged model, oauth_token must be empty
  24
+    Token token = new Token("", "");
  25
+    OAuthService service = new ServiceBuilder().apiKey(key).apiSecret(secret).provider(EchoApi.class).build();
  26
+
  27
+    // Now let's go and ask for a protected resource!
  28
+    System.out.println("Now we're going to access a protected resource...");
  29
+    OAuthRequest request = new OAuthRequest(Verb.POST, PROTECTED_RESOURCE_URL);
  30
+    request.addBodyParameter("content", "your valid activity streams xml");
  31
+    service.signRequest(token, request);
  32
+    Response response = request.send();
  33
+    System.out.println();
  34
+    System.out.println(response.getCode());
  35
+    System.out.println(response.getBody());
  36
+
  37
+    System.out.println();
  38
+    System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
  39
+  }
  40
+}
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.